LeetCode/solutions/344. Reverse String.md
2019-09-13 23:08:41 +08:00

19 lines
462 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [344. Reverse String](https://leetcode.com/problems/reverse-string/description/)
# 思路
翻转字符串。
注意交换元素时最好用标准库里的swap快一些。
# C++
```C++
class Solution {
public:
string reverseString(string s) {
int low = 0, high = s.size() - 1;
while(low < high){
swap(s[low++], s[high--]); // 库里的swap比自己写的要快一些
}
return s;
}
};
```