|
1 | 1 | package com.fishercoder.solutions;
|
2 | 2 |
|
3 |
| -/** |
4 |
| - * 482. License Key Formatting |
5 |
| - * |
6 |
| - * Now you are given a string S, which represents a software license key which we would like to format. |
7 |
| - * The string S is composed of alphanumerical characters and dashes. |
8 |
| - * The dashes split the alphanumerical characters within the string into groups. |
9 |
| - * (i.e. if there are m dashes, the string is split into m+1 groups). |
10 |
| - * The dashes in the given string are possibly misplaced. |
11 |
| - * We want each group of characters to be of length K |
12 |
| - * (except for possibly the first group, which could be shorter, but still must contain at least one character). |
13 |
| - * To satisfy this requirement, we will reinsert dashes. Additionally, all the lower case letters in the string must be converted to upper case. |
14 |
| - * So, you are given a non-empty string S, representing a license key to format, and an integer K. |
15 |
| - * And you need to return the license key formatted according to the description above. |
16 |
| -
|
17 |
| - Example 1: |
18 |
| - Input: S = "2-4A0r7-4k", K = 4 |
19 |
| - Output: "24A0-R74K" |
20 |
| - Explanation: The string S has been split into two parts, each part has 4 characters. |
21 |
| -
|
22 |
| - Example 2: |
23 |
| - Input: S = "2-4A0r7-4k", K = 3 |
24 |
| - Output: "24-A0R-74K" |
25 |
| - Explanation: The string S has been split into three parts, each part has 3 characters except the first part as it could be shorter as said above. |
26 |
| -
|
27 |
| - Note: |
28 |
| - The length of string S will not exceed 12,000, and K is a positive integer. |
29 |
| - String S consists only of alphanumerical characters (a-z and/or A-Z and/or 0-9) and dashes(-). |
30 |
| - String S is non-empty. |
31 |
| - */ |
32 | 3 | public class _482 {
|
33 | 4 | public static class Solution1 {
|
34 | 5 | public String licenseKeyFormatting(String S, int K) {
|
|
0 commit comments