Create 344. Reverse String.md

This commit is contained in:
唐树森 2018-10-04 23:27:59 +08:00 committed by GitHub
parent 38e74de772
commit 708438f314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

18
344. Reverse String.md Normal file
View File

@ -0,0 +1,18 @@
# [344. Reverse String](https://leetcode.com/problems/reverse-string/description/)
# 思路
翻转字符串。
注意交换元素时最好用标准库里的swap快一些。
# 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;
}
};
```