【leetcode】344. Reverse String
problem
solution:
class Solution {
public:
void reverseString(vector<char>& s) {
vector<char> temp(s.size(), '');
for(int i=s.size()-; i>=; i--)
{
temp[i] = s[s.size()-i-];
}
for(int i=; i<s.size(); i++)
{
s[i] = temp[i];
}
}
};
solution2:
class Solution {
public:
void reverseString(vector<char>& s) {
int left = , right = s.size()-;
while(left<right)
{
char tmp = s[left];
s[left++] = s[right];
s[right--] = tmp;
}
}
};
参考
1. Leetcode_344_Reverse String;
完
【leetcode】344. Reverse String的更多相关文章
- 【LeetCode】#344 Reverse String
[Question] Write a function that takes a string as input and returns the string reversed. Example: G ...
- 【LeetCode】344. Reverse String 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 新构建字符串 原地翻转 日期 题目地址:https://lee ...
- 【一天一道LeetCode】#344. Reverse String
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
- 【LeetCode】541. Reverse String II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...
- 【leetcode】557. Reverse Words in a String III
Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-i ...
- 【LeetCode】481. Magical String 解题报告(Python)
[LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...
- 【LeetCode】880. Decoded String at Index 解题报告(Python)
[LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 【LeetCode】151. Reverse Words in a String
Difficulty: Medium More:[目录]LeetCode Java实现 Description Given an input string, reverse the string w ...
- 【LeetCode】557. Reverse Words in a String III 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...
随机推荐
- vijos1448校门外的树
描述 校门外有很多树,有苹果树,香蕉树,有会扔石头的,有可以吃掉补充体力的……如今学校决定在某个时刻在某一段种上一种树,保证任一时刻不会出现两段相同种类的树,现有两个操作:K=1,K=1,读入l.r表 ...
- C++三大特性 封装 继承 多态
C++ 三大特性 封装,继承,多态 封装 定义:封装就是将抽象得到的数据和行为相结合,形成一个有机的整体,也就是将数据与操作数据的源代码进行有机的结合,形成类,其中数据和函数都是类的成员,目的在于将对 ...
- Struts 2 初步入门(六)之处理结果类型
Struts2 处理流程: 用户请求--->struts框架--->Action控制器--->struts框架--->视图资源 xml配置文件里: <result nam ...
- qt资源加载出错
-1: error: No rule to make target '../InteractivePlayer/style.qss', needed by 'debug/qrc_res.cpp'. ...
- thinkphp 3.2 加载第三方库 第三方命名空间库
tp 自动加载的介绍: http://document.thinkphp.cn/manual_3_2.html#autoload 第三方库不规范库 不适用命名空间的库 可以使用import函数导入,其 ...
- 顺序容器----顺序容器操作,vector对象如何增长,额外的string操作,容器适配器
一.顺序容器操作 1.向顺序容器添加元素 向顺序容器(array除外)添加元素的操作: 操作 说明 c.push_back(t) 在c的尾部创建一个值为t的元素.返回void c.emplace_ba ...
- LY.JAVA面向对象编程.内部类
2018-07-18 10:14:48 /* 内部类概述: 把类定义在其他类的内部,这个类就被称为内部类. 举例:在类A中定义了一个类B,类B就是内部类. 内部的访问特点: A:内部类可以直接访问外部 ...
- ie浏览器get url返回404问题
昨晚同事说之前给的接口不能get方式的,直接在ie浏览器访问返回404,说明是参数有问题. 同样的接口使用curl和postman请求都正常,其他ie之外的浏览器也都正常响应. 记录下排查过程: 问题 ...
- C#中使用FFMPEG切割、合并视频。
参考网址:https://blog.csdn.net/samwang_/article/details/70332924 使用前先确保电脑已经安装了FFMPEG,并且配置好环境变量.检测是否安装配置好 ...
- Module loader:模块加载器
<p data-height="265" data-theme-id="0" data-slug-hash="XpqRmq" data ...