482. License Key Formatting Easy
1/**
2 * [482] License Key Formatting
3 *
4 * You are given a license key represented as a string s that consists of only alphanumeric characters and dashes. The string is separated into n + 1 groups by n dashes. You are also given an integer k.
5 * We want to reformat the string s such that each group contains exactly k characters, except for the first group, which could be shorter than k but still must contain at least one character. Furthermore, there must be a dash inserted between two groups, and you should convert all lowercase letters to uppercase.
6 * Return the reformatted license key.
7 *
8 * Example 1:
9 *
10 * Input: s = "5F3Z-2e-9-w", k = 4
11 * Output: "5F3Z-2E9W"
12 * Explanation: The string s has been split into two parts, each part has 4 characters.
13 * Note that the two extra dashes are not needed and can be removed.
14 *
15 * Example 2:
16 *
17 * Input: s = "2-5g-3-J", k = 2
18 * Output: "2-5G-3J"
19 * Explanation: The string s has been split into three parts, each part has 2 characters except the first part as it could be shorter as mentioned above.
20 *
21 *
22 * Constraints:
23 *
24 * 1 <= s.length <= 10^5
25 * s consists of English letters, digits, and dashes '-'.
26 * 1 <= k <= 10^4
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/license-key-formatting/
32// discuss: https://leetcode.com/problems/license-key-formatting/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn license_key_formatting(s: String, k: i32) -> String {
38 String::new()
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_482() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.