Skip to content

Instantly share code, notes, and snippets.

@icameling
Created July 19, 2022 04:00
Show Gist options
  • Save icameling/c1534856bf3af4fee350d9aacb5586ab to your computer and use it in GitHub Desktop.
Save icameling/c1534856bf3af4fee350d9aacb5586ab to your computer and use it in GitHub Desktop.
#字符串 #反转字符串 II
class Solution {
public:
string reverseStr(string s, int k) {
int n = 0;
for (int i = 0; i < s.size(); i += (2*k)) {
if (i + k <= s.size())
reverse(s.begin() + i, s.begin() + i + k);
else
reverse(s.begin() + i, s.end());
}
return s;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment