344. Reverse String
2018-03-07 20:19
246 查看
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 i = 0, j = s.length() - 1;
while(i < j){
swap(s[i], s[j]);
i++;
j--;
}
return s;
}
};
Given s = "hello", return "olleh".class Solution {
public:
string reverseString(string s) {
int i = 0, j = s.length() - 1;
while(i < j){
swap(s[i], s[j]);
i++;
j--;
}
return s;
}
};
相关文章推荐
- #leetcode# 344 Reverse String
- 344. Reverse String
- LeetCode笔记:344. Reverse String
- [leetcode 344]Reverse String
- 344. Reverse String
- 344. Reverse String
- 344. Reverse String
- 344. Reverse String
- (leetcode)344. Reverse String
- LeetCode344. Reverse String
- 【leetcode】【Easy】【344. Reverse String】【string】【two pointers】
- leetcode344. Reverse String
- 344. Reverse String
- 344. Reverse String
- String:344. Reverse String
- 344. Reverse String -- Python
- [leetcode]-344. Reverse String(C语言)
- 344. Reverse String
- LeetCode344—Reverse String
- 344. Reverse String