【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 ...
随机推荐
- 十八、Spring框架(AOP)
一.AOP(基于XML方式配置AOP) AOP(Aspect Oriented Program):面向切面编程.思想是:把功能分为核心业务功能和周边功能. 所谓核心业务功能:比如登录,增删改数据都叫做 ...
- linux network
Linux 1◆ 提供连接 2◆ connection baidu.com 3◆ vm tools install Reboot
- 解决eclipse/myeclipse导入项目时出现红色叹号的方法
- Win10系列:C#应用控件基础5
ListBox控件 上一小节介绍的ComboBox控件在外观上仅显示当前选中的选项,通过单击此控件文本框才能看到其他选项,而ListBox控件能够以列表形式始终显示选项.在ListBox控件中可以添加 ...
- java高级⑴
1.之前我们学过 数组: 数组的特点: 01. 长度一旦被定义,不允许被改变 02. 在内存中开辟一连串连续的空间! 那么现在有一个需求: 让我们定义一个数组 来 保存 新闻信息!!! 问题: 01. ...
- Fedora防火墙配置
简介: Fedora 18以及之后的版本,防火墙的管理不再基于iptables,而基于firewall的东西.firewall的功能相对复杂一些,可以控制服务,控制端口,设置安全区域,设置端口转发等功 ...
- 【转载】《Learn More Study Less》整体性学习方法
原文 忘记在哪里看到这本书的介绍了,据说是一个小子自学1年,完成了4年麻省理工的课程,然后写了一本他学习方法的书.我搜了一下,居然中英文版都有,就花时间好好读了一遍,就是这本. 以下是这本书的完整笔记 ...
- win10企业版激活
slmgr.vbs /upk slmgr /ipk NPPR9-FWDCX-D2C8J-H872K-2YT43 slmgr /skms zh.us.to slmgr /ato
- Map中根据条件删除元素
今天在写程序过程中,需要根据判断条件删除一个Map中的相应数据,我自然而然想到可以通过调用Map中的remove(Object key)函数进行删除:代码如下: public Map<Doubl ...
- Cracking The Coding Interview 3.5
//Implement a MyQueue class which implements a queue using two stacks. #include <iostream> #in ...