Skip to content

Commit a37fe47

Browse files
authored
Create 482. License Key Formatting.java
1 parent 6b5eedb commit a37fe47

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

482. License Key Formatting.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class Solution {
2+
public String licenseKeyFormatting(String S, int K) {
3+
String pre = S.replace("-", "");
4+
StringBuilder sb = new StringBuilder();
5+
6+
for (int i = 0; i < pre.length(); i++) {
7+
sb.append(pre.charAt(pre.length() - 1 - i));
8+
if (i % K == (K-1) && (i != pre.length() - 1)) {
9+
sb.append("-");
10+
}
11+
}
12+
13+
return sb.reverse().toString().toUpperCase();
14+
}
15+
}

0 commit comments

Comments
 (0)