394. Decode String Medium
1/**
2 * [394] Decode String
3 *
4 * Given an encoded string, return its decoded string.
5 * The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.
6 * You may assume that the input string is always valid; there are no extra white spaces, square brackets are well-formed, etc. Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there will not be input like 3a or 2[4].
7 * The test cases are generated so that the length of the output will never exceed 10^5.
8 *
9 * Example 1:
10 *
11 * Input: s = "3[a]2[bc]"
12 * Output: "aaabcbc"
13 *
14 * Example 2:
15 *
16 * Input: s = "3[a2[c]]"
17 * Output: "accaccacc"
18 *
19 * Example 3:
20 *
21 * Input: s = "2[abc]3[cd]ef"
22 * Output: "abcabccdcdcdef"
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= s.length <= 30
28 * s consists of lowercase English letters, digits, and square brackets '[]'.
29 * s is guaranteed to be a valid input.
30 * All the integers in s are in the range [1, 300].
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/decode-string/
36// discuss: https://leetcode.com/problems/decode-string/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn decode_string(s: String) -> String {
42 String::new()
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_394() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.