File tree 2 files changed +19
-1
lines changed 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 125
125
| 463 | [ Island Perimeter] ( https://leetcode.com/problems/island-perimeter ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/IslandPerimeter.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/island_perimeter.py ) |
126
126
| 475 | [ Heaters] ( https://leetcode.com/problems/heaters ) | Medium | |
127
127
| 476 | [ Number Complement] ( https://leetcode.com/problems/number-complement ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/NumberComplement.java ) |
128
- | 482 | [ License Key Formatting] ( https://leetcode.com/problems/license-key-formatting ) | Easy | |
128
+ | 482 | [ License Key Formatting] ( https://leetcode.com/problems/license-key-formatting ) | Easy | [ ![ Java ] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/LicenseKeyFormatting.java ) |
129
129
| 485 | [ Max Consecutive Ones] ( https://leetcode.com/problems/max-consecutive-ones ) | Easy | |
130
130
| 492 | [ Construct the Rectangle] ( https://leetcode.com/problems/construct-the-rectangle ) | Easy | |
131
131
| 496 | [ Next Greater Element I] ( https://leetcode.com/problems/next-greater-element-i ) | Easy | |
Original file line number Diff line number Diff line change
1
+ import java .util .Arrays ;
2
+
3
+ public class LicenseKeyFormatting {
4
+ public String licenseKeyFormatting (String S , int K ) {
5
+ String [] groups = S .split ("-" );
6
+ String characters = String .join ("" , groups ).toUpperCase ();
7
+
8
+ StringBuilder result = new StringBuilder ();
9
+ for (int index = characters .length () - 1 , counter = 0 ; index >= 0 ; index --, counter ++) {
10
+ if (counter % K == 0 && counter != 0 ) {
11
+ result .append ('-' );
12
+ }
13
+ result .append (characters .charAt (index ));
14
+ }
15
+
16
+ return result .reverse ().toString ();
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments