LeetCode 344. Reverse String 对撞指针
2017-05-02 15:11
363 查看
一、题目
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
题意:给定一个字符串,反转输出。
类似的对撞指针的方法。
class Solution {
public:
string reverseString(string s) {
int left=0,right=s.length()-1;
while(left<right)
{
swap(s[left],s[right]);
left++;
right--;
}
return s;
}
};
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
题意:给定一个字符串,反转输出。
类似的对撞指针的方法。
class Solution {
public:
string reverseString(string s) {
int left=0,right=s.length()-1;
while(left<right)
{
swap(s[left],s[right]);
left++;
right--;
}
return s;
}
};
相关文章推荐
- leetcode 125. Valid Palindrome 344.Reverse String与对撞指针解法
- 【编程】【leetcode】344. Reverse String
- LeetCode344. Reverse String
- LeetCode 344. Reverse String(Java)
- [LeetCode]344. Reverse String
- LeetCode 第 344 题(Reverse String)
- leetCode 344. Reverse String 字符串
- leetcode-344. Reverse String
- leetcode 344. Reverse String
- LeetCode 344. Reverse String
- 刷题的日常[Leetcode]——344)reverse string
- LeetCode-344:Reverse String
- leetcode - 344. Reverse String
- leetcode_344 Reverse String
- leetcode_c++: Reverse String(344)
- leetcode 344 Reverse String
- [Leetcode] 344. Reverse String 解题报告
- Leetcode 344 Reverse String
- <LeetCode>344. Reverse String
- LeetCode 344. Reverse String(字符串翻转)