simple solution


  • 0
            StringBuilder sb = new StringBuilder();
            int len = s.length(), count = 0;
            char []ch = s.toCharArray();
            for(int i = len -1; i >= 0; i--){
                if(ch[i] == '-')continue;
                else{
                    sb.insert(0, Character.toUpperCase(ch[i]));
                    count ++;
                    if(count == K){
                          sb.insert(0, "-");
                          count = 0;
                    }
                }
            }
            if(sb.length() == 0) return "";
            if(sb.charAt(0) == '-') sb.deleteCharAt(0);
            return sb.toString();
        }
    

Log in to reply
 

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