[抄题]:

[暴力解法]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩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. (转)Android自定义属性时format选项( <attr format="reference" name="background" /> )

    Android自定义属性时format选项可以取用的值   1. reference:参考某一资源ID. (1)属性定义: [html] view plaincopyprint? <declar ...

  2. JavaFX 之自定义窗口标题栏(二)

    一.问题场景 PC客户端登录界面仿QQ,上边显示图片,下边显示输入框和登录按钮.而JavaFX默认的窗口,不满足需求. 二.解决思路 隐藏窗口默认的标题栏,使用创建label对象,使用css将按钮图片 ...

  3. pandas之DateFrame

    float_df = pd.DataFrame((0.45*np.arange(1,9)).reshape(4,2), index=[1,2,3,4], columns=['col_one', 'co ...

  4. Unit04: JSP基本语法 、 JSP运行原理

    Unit04: JSP基本语法 . JSP运行原理 hello.jsp <%@page pageEncoding="utf-8"%> <!doctype html ...

  5. C语言实现简单的单向链表(创建、插入、删除)及等效STL实现代码

    实现个算法,懒得手写链表,于是用C++的forward_list,没有next()方法感觉很不好使,比如一个对单向链表的最简单功能要求: input: 1 2 5 3 4 output: 1-> ...

  6. FPGA时序约束一点总结

    时序约束的一点总结. 打拍.掌握好时序. 手动分配位置,这个不是一定有效. 打破层级或者物理综合,或者自动加流水等综合优化参数调整. 根据实际情况使用异步时钟策略. 换速度更快的片子. 最也进接手一个 ...

  7. rtmp直播推流(一)--flv格式解析与封装

    flv文件格式分析,可参看RTMP中FLV流到标准h264.aac的转换,该文章写的很清晰. flv封装格式解析,可参看视音频数据处理入门:FLV封装格式解析,文章图文并貌,很直观. flv文件封装, ...

  8. python is 和 == 的区别

    一.is 和 == 的区别 == 比较 比较的俩边的值 is 比较 比较的是内存地址 id() 二.小数据池 数字小数据池的范围 -5 ~ 256 字符串中如果有特殊字符他们的内存地址就不一样 字符串 ...

  9. 【转】Jmeter测试报表相关参数说明

    Jmeter测试报表相关参数说明 采用Jmeter测试工具对web系统作的负载测试,得出的响应报表,数据比较难懂,现作一具体说明. 以下是在一次具体负载测试中得出的具体数值,测试线程设置情况为:线程数 ...

  10. ESXI5-WIN2008R2安装域控以及额外域笔记

    每次安装域控都要找教程,每次都没法一次性搞定.写个笔记吧...主要是给自己看的.写的比较含糊.不清楚的可以直接QQ本人. 1.安装WIN2008R2,192.168.188.10 2.上载SLICET ...