3-liner using std::reverse with string::iterator


  • 0

    I think this is just a straightforward string problem to use string::iterator:

        string reverseStr(string s, int k) {
          for (auto i = s.begin(); i < s.end(); i += 2*k)
            reverse(i, min(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.