leetcode541反转字符串 II

1、题目

https://leetcode-cn.com/problems/reverse-string-ii/

2、题意

题解1:

class Solution {
public:
    string reverseStr(string s, int k) {
        for(int i=0;i<s.size();i+=2*k)
        {
            int t = min(i+k,(int)s.size());
            reverse(s.begin()+i,s.begin()+t);
        }
        return s;
    }
};

你可能感兴趣的:(leetcode,leetcode)