-
[LeetCode] 394. Decode StringLeetCode 2021. 12. 19. 12:05728x90
https://leetcode.com/problems/decode-string/
Decode String - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Decode String - Medium

전체 풀이 코드
class Solution { public: string decodeString(string s) { return run(1,s); } string run(int cnt, string s) { string ret="", temp=""; int chk = 0, t = 0; for (int c=0; c<cnt; c++) { for (int i=0; i<s.size(); i++) { if (s[i]>='0' && s[i]-'0'<=9 && chk==0) t = t*10 + s[i]-'0'; else if (s[i]=='[') { if (chk) temp=temp+s[i]; chk++; } else if (s[i]==']') { chk--; if (!chk) ret = ret + run(t,temp), t=0, temp = ""; else temp = temp+s[i]; } else if (chk) temp = temp + s[i]; else ret = ret+ s[i]; } } return ret; } };'LeetCode' 카테고리의 다른 글
[LeetCode] 116. Populating Next Right Pointers in Each Node (0) 2021.12.29 [LeetCode] 1200. Minimum Absolute Difference (0) 2021.12.20 [LeetCode] 1306. Jump Game III (0) 2021.12.09 [LeetCode] 563. Binary Tree Tilt (0) 2021.12.08 [LeetCode] 120. Triangle (0) 2021.12.03