public class Solution {
public string ReverseString(string s) {
var list = s.Reverse();
StringBuilder sb = new StringBuilder(); foreach (var c in list)
{
sb.Append(c);
} //Console.WriteLine(sb.ToString());
return sb.ToString();
}
}

https://leetcode.com/problems/reverse-string/#/description

下面是使用C++的解决方案,不实用api:

class Solution {
public:
string reverseString(string s) {
string temp = "";
for (int i = s.length() - ; i >= ; i--)
{
temp += s[i];
}
return temp;
}
};

这道题目有所变化,原来的要求是返回string,现在的要求是不返回任何值,而是在原来的字符串上直接修改。 下面使用python实现新的要求:

 class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
n = len(s)
i,j = ,n-
while i < j:
s[j],s[i] = s[i],s[j]
i +=
j -=

leetcode344的更多相关文章

  1. 【算法训练营day8】LeetCode344. 反转字符串 LeetCode541. 反转字符串II 剑指Offer05. 替换空格 LeetCode151. 翻转字符串里的单词 剑指Offer58-II. 左旋转字符串

    [算法训练营day8]LeetCode344. 反转字符串 LeetCode541. 反转字符串II 剑指Offer05. 替换空格 LeetCode151. 翻转字符串里的单词 剑指Offer58- ...

  2. LeetCode344:Reverse String@Python

    Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...

  3. 每天一道LeetCode--344. Reverse String

    Write a function that takes a string as input and returns the string reversed. Example:Given s = &qu ...

  4. leetcode344——Reverse String(C++)

    Write a function that takes a string as input and returns the string reversed. Example:Given s = &qu ...

  5. [Swift]LeetCode344. 反转字符串 | Reverse String

    Write a function that takes a string as input and returns the string reversed. Example 1: Input: &qu ...

  6. 面试题:反转字符串(leetcode344)

    编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 char[] 的形式给出. 不要给另外的数组分配额外的空间,你必须原地修改输入数组.使用 O(1) 的额外空间解决这一问题. 你可以 ...

  7. leetcode344 反转字符串 c++实现

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

  8. LeetCode-344:Reverse String

    This  is a  "Pick One" Problem :[Problem:344-Reverse String] Write a function that takes a ...

  9. LeetCode344 反转字符串

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

随机推荐

  1. Tomcat:Several ports are already in use问题

    Several ports (8005, 8080, 8009) required by Tomcat v6.0 Server at localhost are already in use. The ...

  2. Linux引导启动顺序

    1.所有的__init函数在区段.initcall.init中还保存了一份函数指针,在初始化时内核会通过这些函数指针调用这些__init函数,并在整个初始化完成后,释放整个init区段(包括.init ...

  3. leetcode:Pascal's Triangle【Python版】

    1.这道题一次提交就AC了: 2.以前用C语言实现的话,初始化二维数组全部为0,然后每行第一个元素为1,只需要用a[i][j] = a[i-1][j]+a[i-1][j-1]就可以了: 3.在Pyth ...

  4. PHP中数组的各种用法

    $a = 'false';if($a){ echo '好坑';}输出好坑,得转换成布尔值才行哦. in_array $people = array("Bill", "St ...

  5. JUC集合之 ConcurrentLinkedQueue

    ConcurrentLinkedQueue介绍 ConcurrentLinkedQueue是线程安全的队列,它适用于"高并发"的场景. 它是一个基于链接节点的无界线程安全队列,按照 ...

  6. Linux elasticsearch 安装 遇到的问题

    备注:我的 Linux 测试机  是2G 内存的 ,估计内存小于 我的内存肯定会出这个问题 .(安装的最新版6.3.2) 1.  下载文件  解压 2 .试着 运行 bin 下面的 elasticse ...

  7. HBase常用指令

    disable 'smsFlow'drop 'smsFlow'create 'smsFlow','info','partition'count 'smsFlow'scan 'smsFlow' trun ...

  8. 【jemter】HTTP请求参数化

    HTTP请求参数化:就是把URL的参数项做参数化处理 我们现在要对子猴博客来进行一番压力测试,压力测试对象为随机的几个网页链接,这几个链接是写在一个文本文件中的,在压力测试的时候会随机读取. 1.  ...

  9. linux vnc 安装

    http://blog.csdn.net/mchdba/article/details/49306383

  10. bootstrap+font-awesome表单

    bootstrap+font-awesome表单 <form action="" class="form-horizontal col-sm-offset-4&qu ...