C++ | Leetcode C++题解之第541题反转字符串II
题目:
题解:
class Solution {
public:string reverseStr(string s, int k) {int n = s.length();for (int i = 0; i < n; i += 2 * k) {reverse(s.begin() + i, s.begin() + min(i + k, n));}return s;}
};
题目:
题解:
class Solution {
public:string reverseStr(string s, int k) {int n = s.length();for (int i = 0; i < n; i += 2 * k) {reverse(s.begin() + i, s.begin() + min(i + k, n));}return s;}
};