[抄题]:

[暴力解法]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩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. MySQL主从报错解决:Failed to initialize the master info structure

    大清早收到一个MySQL的自定义语言告警 :replication interrupt,看来是主从同步报错了. 登陆MySQL,执行 show slave status \G 发现salve已经停止了 ...

  2. 监控mysql状态并发送Email

    */10 * * * *  /shell/mysql_status.sh > /dev/null 2>&1 #!/bin/bash port55=`/usr/sbin/lsof - ...

  3. 历届试题 Excel地址

    问题描述 Excel单元格的地址表示很有趣,它使用字母来表示列号. 比如, A表示第1列, B表示第2列, Z表示第26列, AA表示第27列, AB表示第28列, BA表示第53列, .... 当然 ...

  4. SpringBoot运行报Address already in use: bind

    java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method) at sun.n ...

  5. (转)win7+iis7.5+asp.net下 CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files 解决方案

    本文转载自:http://www.cnblogs.com/finesite/archive/2011/01/28/1946940.html 网上搜的解决方案但在我的环境下仍旧没有解决,我的方法如下: ...

  6. 使用SLF4J和LOGBACK (一 : 基本使用)

    1.SLF4J是什么? slf4j是一个日志门面,它不是具体的日志实现框架,而是提供了通用的日志接口,按个人理解来说,是通过接口实现多态,来满足应用在不同日志框架间切换的需求. 例如在程序中我们需要记 ...

  7. Hadoop Map/Reduce的工作流

    问题描述 我们的数据分析平台是单一的Map/Reduce过程,由于半年来不断地增加需求,导致了问题已经不是那么地简单,特别是在Reduce阶段,一些大对象会常驻内存.因此越来越顶不住压力了,当前内存问 ...

  8. 缺乏libaio包导致报The server quit without updating PID file

    背景: 直接解压安装mysql5.7.18,解压mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz,直接拷贝另外一台数据库的数据目录,启动mysql过程无日志输出,报E ...

  9. PyQt5+python+pycharm开发环境配置

    Qt Designer的安装方法 使用Qt Designer可以使用GUI的方式快速生成PyQt代码,本文介绍Qt Designer的安装以及在PyCharm中的配置方法. pip install P ...

  10. Git学习之常用的命令

    配置git git config --global user.name "你的github用户名" git config --global user.email "你的G ...