leetcode344
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的更多相关文章
- 【算法训练营day8】LeetCode344. 反转字符串 LeetCode541. 反转字符串II 剑指Offer05. 替换空格 LeetCode151. 翻转字符串里的单词 剑指Offer58-II. 左旋转字符串
[算法训练营day8]LeetCode344. 反转字符串 LeetCode541. 反转字符串II 剑指Offer05. 替换空格 LeetCode151. 翻转字符串里的单词 剑指Offer58- ...
- LeetCode344:Reverse String@Python
Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...
- 每天一道LeetCode--344. Reverse String
Write a function that takes a string as input and returns the string reversed. Example:Given s = &qu ...
- leetcode344——Reverse String(C++)
Write a function that takes a string as input and returns the string reversed. Example:Given s = &qu ...
- [Swift]LeetCode344. 反转字符串 | Reverse String
Write a function that takes a string as input and returns the string reversed. Example 1: Input: &qu ...
- 面试题:反转字符串(leetcode344)
编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 char[] 的形式给出. 不要给另外的数组分配额外的空间,你必须原地修改输入数组.使用 O(1) 的额外空间解决这一问题. 你可以 ...
- leetcode344 反转字符串 c++实现
编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man, a p ...
- LeetCode-344:Reverse String
This is a "Pick One" Problem :[Problem:344-Reverse String] Write a function that takes a ...
- LeetCode344 反转字符串
编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man, a p ...
随机推荐
- bulid-tool
Build tool 中文构建工具.构建工具能够帮助你创建一个可重复的.可靠的.携带的且不需要手动干预的构建.构建工具是一个可编程的工具,它能够让你以可执行和有序的任务来表达自动化需求.假设你想要编译 ...
- RPC好,还是RESTful好?
看到知乎上有这样一个问题 WEB开发中,使用JSON-RPC好,还是RESTful API好? 还有其他优秀的推荐方案吗? -------------------------------------- ...
- B树就想到这个
比如要查找60 先在根结点中查,根结点里面有 17 35这2个关键字, 60 > 35,则从右边开始查找 p3指针开始查找 , 到了第二层的最右边的那个结点开始查找 , 里面有 65 8 ...
- vue 回车自动登录
原理: 在密码输入框加入事件:@keyup.enter.native 登录button加入事件:@click 代码: pug 语法: el-form(ref="loginForm" ...
- GitHub10岁之际HanLP自然语言处理包用户量跃居榜首
在本周,GitHub终于度过了属于它自己的十周岁生日.这个在2008年由3个来自旧金山的年轻人创建的基于Git的代码托管网站,先后超越了元老级的SourceForge和背景强大的Google Code ...
- [转]oracle导入提示“IMP-00010:不是有效的导出文件,头部验证失败”的解决方案
这是由于导出的dmp文件与导入的数据库的版本不同造成的用Notepad++查看了dmp文件,在头部具修改成你将导入目标数据库的版本号以下对应的版本号: 11g R2:V11.02.00 11g R1: ...
- C#使用WebService 常见问题处理
C#使用WebService 一.新建webservice 新建项目→asp.net Web服务应用程序 或者在现有项目中 点击右键 新建web服务程序asmx 只要在webservice类里面 ...
- 2013-7-28 802.11n帧聚合
芯片开发阶段的帧聚合迥异于商用AP,前者更偏向实现过程,后者偏向结果.也就是说用户在使用商用设备时不会管你特性是如何实现的,他们只关心效果,开启这个功能能否实实在在的提高AP的吞吐量. 网上搜索了众多 ...
- 2018-2019 Exp2 后门原理与实践
2018-2019 Exp2 后门原理与实践 目录 一.实验内容说明及基础问题回答 二.工具准备 查看WindowsIP和LinuxIP Windows获得Linuxshell Linux 获得Win ...
- [转] Maven.pom.xml 配置示例
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...