Open rocksc30 opened 1 year ago
// 使用库函数进行交换
class Solution {
public:
string reverseStr(string s, int k) {
int len = s.length();
for(int index = 0 ; index < len ; index += 2 * k)
{
int n = 0;
auto begin = s.begin();
auto end = s.begin();
if(index + k > len )
n = len ;
else
n = index + k;
std::advance(begin,index);
std::advance(end, n );
std::reverse(begin,end);
}
return s;
}
};