3 lines C++ solution


  • 0
    A
    class Solution {
    public:
        string reverseStr(string s, int k) {
            for (int i = 0; i < s.length(); i += k * 2)
                reverse(s.begin() + i, i + k <= s.length() ? s.begin() + i + k : s.end());
            return s;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.