Java naive solution using queue and stringBuilder


  • 0
    X
        StringBuilder sb = new StringBuilder();
        for (int i = s.length() - 1; i >= 0; i--)
            if (s.charAt(i) != '-')
                sb.append(sb.length() % (k + 1) == k ? '-' : "").append(s.charAt(i));
        return sb.reverse().toString().toUpperCase();

Log in to reply
 

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