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. hdu2602 DP (01背包)

    题意:有一个容量 volume 的背包,有一个个给定体积和价值的骨头,问最多能装价值多少. 经典的 01 背包问题不谈,再不会我就要面壁了. 终于有一道题可以说水过了 ……心好累 #include&l ...

  2. IP相关的方法

    1.验证是否为IP地址 def isIP(ip, with_netmask=True): """ 判断IP的格式是否正确 :param ip: IP字符串 :param ...

  3. 【java编程】重写HashCode和equals方法

    [一]重写equals方案的规则 equals方法本来的原则 1.类的每个实例本质上都是唯一的. 2.不关心类是否提供了“逻辑相等”的测试功能 3.超类已经覆盖了equals,从超类继承过来的行为对于 ...

  4. jsp页面九大内置对象

    资源转载自网上,不可用于商用,学习可以.内置对象又叫隐式对象/隐含对象是由WEB容器加载的一组类的实例,不需要预先声明就可以在脚本代码和表达式中随意使用的对象. 这九大隐式对象可以按照期作用分类为: ...

  5. map和jsonObject 这2中数据结构之间转换

    前台写json直接是:var array = [ ] ; 调用方法:array[index],若是对象,再[“key”] var obj = {''a'':123 , "b":&q ...

  6. nexage video asset tag

    video  ad can't show InLine  must  match   the example ,and   xml content is  Case Sensitive https:/ ...

  7. 构建一个dbt 数据库适配器

    脚手架新的适配器 首先,将odbc适配器模板复制到同一目录中的新文件. 更新dbt / adapters / factory.py以将新适配器包含为类型.还要将类型添加到dbt / contracts ...

  8. 白话 Java Bean

    所谓的Java Bean,就是一个java类,编译后成为了一个后缀名是 .class的文件.这就是Java Bean,不就是Java类吗? 1. 什么是 Java Bean? 很多培训机构在讲java ...

  9. Lucene.Net 入门级实例 浅显易懂。。。

    Lucene.Net 阅读目录 开始 Lucene简介 效果图 Demo文件说明 简单使用 重点类的说明 存在问题 调整后 Lucene.Net博文与资源下载 做过站内搜索的朋友应该对Lucene.N ...

  10. Linux内存管理和应用

    [作者:byeyear.首发于cnblogs,转载请注明.联系:east3@163.com] 本文对Linux内存管理使用到的一些数据结构和函数作了简要描述,而不深入到它们的内部.对这些数据结构和函数 ...