[Algorithms] LeetCode 344. 反转字符串
Categories Algorithms String
Tags
来源:代码随想录
单指针
class Solution {
public:
void reverseString(vector<char>& s) {
for (int i = 0; i < s.size() / 2; i++) {
char temp = s[i];
s[i] = s[s.size() - 1 - i];
s[s.size() - 1 - i] = temp;
}
}
};
也可以用swap函数。
Page views: Loading... · Visitors: Loading...
Except where otherwise noted, original content on this site is dedicated to the public domain under CC0 1.0.
Powered by Hexo & Theme mdsuper
沪ICP备2026040813号