asp网站建设,哈尔滨市招标网,电商购物网站开发需求分析,小程序怎么做出来的leetcode-344. 反转字符串 文章目录 leetcode-344. 反转字符串一.题目描述二.第1次提交(std::reverse)三.第2次提交(左右指针)四.第3次提交(左右指针#xff0c;swap函数)五.第4次提交(左右指针) 一.题目描述 二.第1次提交(std::reverse)
class Solution {public:void revers…leetcode-344. 反转字符串 文章目录 leetcode-344. 反转字符串一.题目描述二.第1次提交(std::reverse)三.第2次提交(左右指针)四.第3次提交(左右指针swap函数)五.第4次提交(左右指针) 一.题目描述 二.第1次提交(std::reverse)
class Solution {public:void reverseString(vectorchar s) {std::reverse(s.begin(), s.end());}
};三.第2次提交(左右指针) class Solution {public:void reverseString(vectorchar s) {int left 0;int right s.size() - 1;while (left right) {auto tmp s[left];s[left] s[right];s[right] tmp;left;right--;}}
};四.第3次提交(左右指针swap函数)
class Solution {public:void reverseString(vectorchar s) {int left 0;int right s.size() - 1;while (left right) {swap(s[left], s[right]);left;right--;}}
};五.第4次提交(左右指针)
class Solution {public:void reverseString(vectorchar s) {for (int i 0, j s.size() - 1; i s.size() / 2; i, j--) {swap(s[i], s[j]);}}
};