problem

344. Reverse String

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的更多相关文章

  1. 【LeetCode】#344 Reverse String

    [Question] Write a function that takes a string as input and returns the string reversed. Example: G ...

  2. 【LeetCode】344. Reverse String 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 新构建字符串 原地翻转 日期 题目地址:https://lee ...

  3. 【一天一道LeetCode】#344. Reverse String

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

  4. 【LeetCode】541. Reverse String II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...

  5. 【leetcode】557. Reverse Words in a String III

    Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-i ...

  6. 【LeetCode】481. Magical String 解题报告(Python)

    [LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...

  7. 【LeetCode】880. Decoded String at Index 解题报告(Python)

    [LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  8. 【LeetCode】151. Reverse Words in a String

    Difficulty: Medium  More:[目录]LeetCode Java实现 Description Given an input string, reverse the string w ...

  9. 【LeetCode】557. Reverse Words in a String III 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...

随机推荐

  1. HTML标签(二)

    一.字体标签 字体标签包含:h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub> ...

  2. vue 中router.go、router.push和router.replace的区别

    router.go(n) 这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n) router.push(location) 想要 ...

  3. 前端开发VScode常用插件

    名称 功能 Auto Close Tag 自动闭合HTML标签 Auto Import Typescript 自动import提示 Auto Rename Tag 修改HTML标签时,自动修改匹配的标 ...

  4. openssl实现双向认证教程(服务端代码+客户端代码+证书生成)

    一.背景说明 1.1 面临问题 最近一份产品检测报告建议使用基于pki的认证方式,由于产品已实现https,商量之下认为其意思是使用双向认证以处理中间人形式攻击. <信息安全工程>中接触过 ...

  5. python 判断变量是否存在 防止报错

    Python判断变量是否存在 方法一:使用try: ... except NameError: .... try: var except NameError: var_exists = False e ...

  6. Chrome使用的plugin

    Chrome使用的plugin   翻译 google翻译 youlict划词翻译     书签   查询书签 neater bookmarks 博客园收藏网页 书签保存 bookmark sysnc ...

  7. swagger注释@API详细说明

    swagger是当前最好用的Restful  API文档生成的开源项目,通过swagger-spring项目实现了springMVC框架的无缝集成功能,方便生成restful风格的接口文档, 同时,s ...

  8. git Please move or remove them before you can merge.

    git clean -d -fx "" 其中  x -----删除忽略文件已经对git来说不识别的文件 d -----删除未被添加到git的路径中的文件 f -----强制运行

  9. 记录一次面试中的HTTP请求相关问题

    1.HTTP中的状态码分别代表什么 比较基础,自行百度.   2.HTTP请求,响应头部content-length用来做什么的 答:Content-Length首部告诉浏览器报文中实体主体的大小.这 ...

  10. linux网络操作 ifconfig命令

    ifconfig 查看已经被激活的网卡详细信息 "ifconfig eth0" 查看特定的网卡信息 [root@ssgao ~]# ifconfig eth0 eth0 Link ...