Created
July 19, 2022 04:00
-
-
Save icameling/c1534856bf3af4fee350d9aacb5586ab to your computer and use it in GitHub Desktop.
#字符串 #反转字符串 II
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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