[抄题]:

[暴力解法]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

还停留在 i < len / 2的阶段,不行,应该是指针对撞问题了

[一句话思路]:

先要把字符串转成数组,再转回来,数据结构白学了?

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

  1. 用.tochararray转成字符串数组,顾名思义了

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

先要把字符串转成数组,再转回来

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

必须是字符串数组才能转

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

Reverse String II 带有index的

[代码风格] :

class Solution {
public String reverseString(String s) {
//corner case
if (s == null) {
return null;
}
int i = 0, j = s.length() - 1;
//convert to char[]
char[] chars = s.toCharArray();
while (i < j) {
char temp = chars[i];
chars[i] = chars[j];
chars[j] = temp; i++;
j--;
}
//convert again
return new String(chars);
//return
}
}

344. Reverse String 最基础的反转字符串的更多相关文章

  1. leetcode 344. Reverse String 、541. Reverse String II 、796. Rotate String

    344. Reverse String 最基础的旋转字符串 class Solution { public: void reverseString(vector<char>& s) ...

  2. Leetcode#344. Reverse String(反转字符串)

    题目描述 编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man ...

  3. 344. Reverse String(C++)

    344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...

  4. [LeetCode] 344 Reverse String && 541 Reverse String II

    原题地址: 344 Reverse String: https://leetcode.com/problems/reverse-string/description/ 541 Reverse Stri ...

  5. LeetCode Javascript实现 344. Reverse String 292. Nim Game 371. Sum of Two Integers

    344. Reverse String /** * @param {string} s * @return {string} */ var reverseString = function(s) { ...

  6. 【leetcode】344. Reverse String

    problem 344. Reverse String solution: class Solution { public: void reverseString(vector<char> ...

  7. 344. Reverse String【easy】

    344. Reverse String[easy] Write a function that takes a string as input and returns the string rever ...

  8. LeetCode 344. Reverse String(反转字符串)

    题目描述 LeetCode 344. 反转字符串 请编写一个函数,其功能是将输入的字符串反转过来. 示例 输入: s = "hello" 返回: "olleh" ...

  9. Leetcode 344 Reverse String 字符串处理

    题意:反转字符串,用好库函数. class Solution { public: string reverseString(string s) { reverse(s.begin(),s.end()) ...

随机推荐

  1. 【转】关于gcc、glibc和binutils模块之间的关系

    原文网址:http://www.mike.org.cn/articles/linux-about-gcc-glibc-and-binutils-the-relationship-between-mod ...

  2. bzoj 2039 [2009国家集训队]employ人员雇佣——二元关系

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2039 用最小割看.对于一组关系 i , j ,如果都选,收益 2*Ei,j,可以看作0,作为 ...

  3. bzoj1588[HNOI2002]营业额统计——双向链表

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1588 简单Splay.但用双向链表做.很好的思路. 1.(离线)按值排序,记下pre和nxt ...

  4. Unit07: document 对象 、 自定义对象 、 事件

    Unit07: document 对象 . 自定义对象 . 事件 知识点: <!DOCTYPE html> <html> <head> <meta chars ...

  5. Warning: skipping non-radio button in group. 的处理

    1)把你的第一个Radio选中group属性: 2)把你“这个组中”的最后一个Raido控件“后”的一个控件(指得是控件添加先后的顺序,可以用ctrl+d来修改顺序)也选中group属性,如最后一个R ...

  6. golang的最简单的文件浏览web服务器

    网上看到的,记录下,备用 package main import ( "net/http" ) func main() { http.Handle("/", h ...

  7. bzoj2184: 任意图的匹配

    Description 每天都要考,每天都要讲,大家注意力都集中不起来了,每天听解题报告时都有人交头接耳(也包括我,呵呵).这样做大大的影响的学习效率(可能吧).于是,有些好奇心重的同学就开始研究,怎 ...

  8. Account银行账户

    package com.hanqi; //账户类 public class Account { String ZhangHao; double CunKuanYuE; Account(String Z ...

  9. 1135 Is It A Red-Black Tree

    题意:给出k个二叉搜索树的前序序列,判断该树是否为红黑树. 红黑树的定义: 结点的颜色非红即黑 根结点的颜色必须是黑色 每个叶子结点(指的是空结点,图中并没有画出来)都是黑色的 如果某个结点为红色,则 ...

  10. JPype:实现在python中调用JAVA

    一.JPype简述 1.JPype是什么? JPype是一个能够让 python 代码方便地调用 Java 代码的工具,从而克服了 python 在某些领域(如服务器端编程)中的不足. 2.JPype ...