C++ code 3 line easy to understand


  • 0
    G

    :

    string reverseStr(string s, int k)
    {
        
       for (int left = 0; left < s.size(); left += 2 * k) 
       {
           reverse(s.begin()+left,s.begin()+left+min(k,int (s.size()-left)));
        }
        return s;
    }

Log in to reply
 

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