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 ...
随机推荐
- ppt标题排版
- Linux设备树
一.设备树编译 1.编译设备树:cd linux-x.xx & make dtbs,生成的dtb在目录linux-x.xx/arch/xxx/boot/dts下 2.反编译dtb,生成dts: ...
- leetcode:Maximum Depth of Binary Tree【Python版】
# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self ...
- streamsets k8s 部署试用
使用k8s 进行 streamsets的部署(没有使用持久化存储) k8s deploy yaml 文件 deploy.yaml apiVersion: extensions/v1beta1 kind ...
- c#问题(按F1或F2键时触发事件)
this.KeyPreview = true;...private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArg ...
- Linux strace命令 一
简介 strace常用来跟踪进程执行时的系统调用和所接收的信号. 在Linux世界,进程不能直接访问硬件设备,当进程需要访问硬件设备(比如读取磁盘文件,接收网络数据等等)时,必须由用户态模式切换至内核 ...
- linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系 主机名: 如果说你没有设置主机名的话,默认是localhost.localdomain 修改配置文件的主机名 # hostnamectl set-hostname ...
- CorelDRAW X4常用快捷键大全
材料/工具 CorelDRAW X4 方法 1 F1:帮助信息 F2:缩小 F3:放大 F4:缩放到将所有对象置于窗口中 F5:手绘(Freehand)工具 F6:矩形(Rectangle)工具 F7 ...
- matlab下将图片序列转化为视频文件 && 将为视频文件转化图片序列
将图片序列转化为视频文件 程序如下: framesPath = 'E:\img\';%图像序列所在路径,同时要保证图像大小相同 videoName = 'Bolt.avi';%表示将要创建的视频文件的 ...
- 6.15-初识JSP、javaweb
一.javaweb web服务器 tomcat C/S 客户端/服务器 B/S 浏览器/服务器 URL: http协议 https 加密的协议 localhost 127.0.0.1 常用web服务器 ...