My Concise Java Solution


  • 0
    4
    public class Solution {
        public String reverseStr(String s, int k) {
            int fast = 0;
            StringBuilder builder = new StringBuilder();
            while(fast < s.length()){
                if((fast / k) % 2 != 1){
                    int len = builder.length();
                    while((fast / k) % 2 != 1 && fast < s.length()){
                        builder.insert(len, s.charAt(fast));
                        fast ++;
                    }
                }
                else{
                    builder.append(s.charAt(fast));
                    fast ++;
                }
            }
            return builder.toString();
        }
    }
    

Log in to reply
 

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