My C++ Solution, use 344.Reverse String and no min operation


  • 0
    E
    class Solution {
    public:
        string reverseString(string s) {
            int i = 0, j = s.size() - 1;
            while(i < j){
                swap(s[i++], s[j--]);
            }
    
            return s;
        }
        string reverseStr(string s, int k) {
            int length = s.length();
            string temp = "";
            for(int i=0;i<length;i+=2*k){
                temp = s.substr(i,k);//no min operation
                temp = reverseString(temp);
                s.replace(i,k,temp);
            }
            return s;
        }
    };

Log in to reply
 

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