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相关推荐

  1. LeetCode344——Reverse String(将字符串反转)

    题目: 解法: class Solution { public:string reverseString(string s) {int i=0,j=s.size()-1;while(i<j){s ...

  2. stone/reverse/string/digit(完美消除)

    stone/reverse/string/digit(完美消除) stone: [问题描述] 平平去海边度假,海边有一片美丽的鹅卵石滩.平平在鹅卵石滩上捡了 $n$ 块美丽的 鹅卵石,并把它们排成一个 ...

  3. LeetCode之Reverse String II

    1.题目 Given a string and an integer k, you need to reverse the first k characters for every 2k charac ...

  4. 【跟Leon一起刷LeetCode】344. Reverse String

    Reverse String Description: Write a function that takes a string as input and returns the string rev ...

  5. Reverse String

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

  6. 定间隔字符翻转(Reverse String II)

    一.学习要点: 1.主要是对剩余字符长度的考虑,大于k的时候,对前k个进行翻转:小于k的时候,对实际个数进行全翻转:本程序中翻转个数用变量x来表示: 二.代码: #include<stdlib. ...

  7. LeetCode之Reverse String

    1.题目: Write a function that takes a string as input and returns the string reversed. Example: Given ...

  8. String | 344. Reverse String

    题目:反转字符串 方法1: class Solution { public:string reverseString(string s) {int m = (s.size() -1) / 2;for( ...

  9. LeetCode 541. Reverse String II

    题目: Given a string and an integer k, you need to reverse the first k characters for every 2k charact ...

最新文章

  1. 14PS中的切图基本操作
  2. Oracle Instanc Client安装命令工具
  3. android响铃停止源代码,android – 如何停止当前正在播放的铃声?
  4. Python调用MongoDB使用心得
  5. 模仿网易(163)首页Ajax功能中的鼠标延时触发
  6. equals()与==的区别
  7. 实例--[QSerialPort]串口通信
  8. 微信小程序头像怎么改变形状_微信小程序头像怎么改
  9. 【一】高等数学上册第一章笔记。
  10. opencv raw转rgb_使用OpenCV实现RGB、HSI、CMYK颜色空间的转换
  11. mbr转gpt 无损 linux,磁盘MBR改成GPT|MBR无损转换GPT分区
  12. 访问hadoop集群时错误:Access denied for user Administrator. Superuser privilege is required
  13. html魔方转动效果,简单说 用CSS做一个魔方旋转的效果
  14. UVa1646 - Edge Case
  15. pr cpu100%_PR插件proDAD4.0.487.1安装教程
  16. crmeb 易联云k4小票打印机相关配置说明
  17. [图形学] 实时体积水和泡沫的渲染
  18. 磁场强度 H、磁通量 Φ、磁感应强度 B
  19. dnf加物理攻击的卡片有哪些_dnf加物理攻击力的宝珠有哪些 dnf物攻宝珠
  20. 【观察】当 SmartX 遇见英特尔傲腾,超融合系统性能突破新极限

热门文章

  1. 第十四天-企业应用架构模式-Web表现模式
  2. Java开发环境搭建及开发软件和服务器安装与配置
  3. 学习微信小程序之css7
  4. Js toString()方法笔记
  5. a(n+1) = f[a(n)] 型递推数列的迭代作图(玩计算器玩出了问题)
  6. MyBatis Review——一对多关系映射配置
  7. 使用 imitator 实现前后端分离开发中的数据模拟与静态资源映射
  8. Windows XP蓝屏故障诊断
  9. BW报表igs服务配置解决中文显示问题
  10. delete删除重复记录方法