MCPcopy
hub / github.com/qiyuangong/leetcode / licenseKeyFormatting

Method licenseKeyFormatting

java/482_License_Key_Formatting.java:2–9  ·  view source on GitHub ↗
(String s, int k)

Source from the content-addressed store, hash-verified

1class Solution {
2 public String licenseKeyFormatting(String s, int k) {
3 // https://leetcode.com/problems/license-key-formatting/discuss/96512/Java-5-lines-clean-solution
4 StringBuilder sb = new StringBuilder();
5 for (int i = s.length() - 1; i >= 0; i--)
6 if (s.charAt(i) != '-')
7 sb.append(sb.length() % (k + 1) == k ? '-' : "").append(s.charAt(i));
8 return sb.reverse().toString().toUpperCase();
9 }
10}

Callers

nothing calls this directly

Calls 1

reverseMethod · 0.45

Tested by

no test coverage detected