1. 程式人生 > >LeetCode.482. License Key Formatting

LeetCode.482. License Key Formatting

https://leetcode.com/problems/license-key-formatting/

class Solution {
    public String licenseKeyFormatting(String S, int K) {
    
        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(); } }