From 643adff4c18383a54b8c4c6d3fb767cf772c55b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=93=20V=C4=83n=20H=C3=B2a?= <56647826+hovanhoa@users.noreply.github.com> Date: Sun, 8 Sep 2024 10:45:53 +0700 Subject: [PATCH] Time: 1 ms (75.07%), Space: 2.3 MB (83.19%) - LeetHub --- 0394-decode-string/0394-decode-string.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/0394-decode-string/0394-decode-string.go b/0394-decode-string/0394-decode-string.go index 46591dd..332c813 100644 --- a/0394-decode-string/0394-decode-string.go +++ b/0394-decode-string/0394-decode-string.go @@ -2,13 +2,14 @@ func decodeString(s string) string { nums, codes := []int{}, []string{} num, code := "", "" for _, c := range s { - if unicode.IsNumber(c) { + if unicode.IsDigit(c) { num += string(c) } else if unicode.IsLetter(c) { code += string(c) } else if c == '[' { n, _ := strconv.Atoi(num) - nums, codes = append(nums, n), append(codes, code) + nums = append(nums, n) + codes = append(codes, code) num, code = "", "" } else if c == ']' { n, c := nums[len(nums)-1], codes[len(codes)-1] @@ -16,5 +17,6 @@ func decodeString(s string) string { nums, codes = nums[:len(nums)-1], codes[:len(codes)-1] } } + return code } \ No newline at end of file