LeetCode344. Reverse String
344. Reverse String
My Submissions QuestionEditorial Solution
Total Accepted: 6975 Total Submissions: 11764 Difficulty: Easy
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = “hello”, return “olleh”.
//方法一:最简单的办法,直接调用 reverse 函数。。
class Solution {
public:string reverseString(string s) {reverse(s.begin(), s.end());return s;}
};//方法二:比较常规的做法,左右两边第一个和倒数第一个调换,第二个和倒数第二个调换...
class Solution {
public:string reverseString(string s) {for(int i = 0; i < s.length() / 2; i++) {swap(s[i], s[s.length() - i - 1]);}return s;}
};
LeetCode344. Reverse String相关推荐
- LeetCode344——Reverse String(将字符串反转)
题目: 解法: class Solution { public:string reverseString(string s) {int i=0,j=s.size()-1;while(i<j){s ...
- stone/reverse/string/digit(完美消除)
stone/reverse/string/digit(完美消除) stone: [问题描述] 平平去海边度假,海边有一片美丽的鹅卵石滩.平平在鹅卵石滩上捡了 $n$ 块美丽的 鹅卵石,并把它们排成一个 ...
- LeetCode之Reverse String II
1.题目 Given a string and an integer k, you need to reverse the first k characters for every 2k charac ...
- 【跟Leon一起刷LeetCode】344. Reverse String
Reverse String Description: Write a function that takes a string as input and returns the string rev ...
- Reverse String
Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...
- 定间隔字符翻转(Reverse String II)
一.学习要点: 1.主要是对剩余字符长度的考虑,大于k的时候,对前k个进行翻转:小于k的时候,对实际个数进行全翻转:本程序中翻转个数用变量x来表示: 二.代码: #include<stdlib. ...
- LeetCode之Reverse String
1.题目: Write a function that takes a string as input and returns the string reversed. Example: Given ...
- String | 344. Reverse String
题目:反转字符串 方法1: class Solution { public:string reverseString(string s) {int m = (s.size() -1) / 2;for( ...
- LeetCode 541. Reverse String II
题目: Given a string and an integer k, you need to reverse the first k characters for every 2k charact ...
最新文章
- 14PS中的切图基本操作
- Oracle Instanc Client安装命令工具
- android响铃停止源代码,android – 如何停止当前正在播放的铃声?
- Python调用MongoDB使用心得
- 模仿网易(163)首页Ajax功能中的鼠标延时触发
- equals()与==的区别
- 实例--[QSerialPort]串口通信
- 微信小程序头像怎么改变形状_微信小程序头像怎么改
- 【一】高等数学上册第一章笔记。
- opencv raw转rgb_使用OpenCV实现RGB、HSI、CMYK颜色空间的转换
- mbr转gpt 无损 linux,磁盘MBR改成GPT|MBR无损转换GPT分区
- 访问hadoop集群时错误:Access denied for user Administrator. Superuser privilege is required
- html魔方转动效果,简单说 用CSS做一个魔方旋转的效果
- UVa1646 - Edge Case
- pr cpu100%_PR插件proDAD4.0.487.1安装教程
- crmeb 易联云k4小票打印机相关配置说明
- [图形学] 实时体积水和泡沫的渲染
- 磁场强度 H、磁通量 Φ、磁感应强度 B
- dnf加物理攻击的卡片有哪些_dnf加物理攻击力的宝珠有哪些 dnf物攻宝珠
- 【观察】当 SmartX 遇见英特尔傲腾,超融合系统性能突破新极限