FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-NOTES/Algorithms/394.Decode-String/solution.cpp at master · moranzcw/LeetCode-NOTES · GitHub
moranzcw
/
LeetCode-NOTES
Public
Notifications
You must be signed in to change notification settings
Fork
77
Star
201
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-NOTES
/
Algorithms
/
394.Decode-String
/
solution.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (29 loc) · 655 Bytes
Breadcrumbs
LeetCode-NOTES
/
Algorithms
/
394.Decode-String
/
solution.cpp
Copy path
File metadata and controls
30 lines (29 loc) · 655 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class
Solution
{
public:
string
DFS
(string s,
int
&k)
{
string ans;
int
cnt =
0
;
while
(k < s.
size
())
{
if
(
isdigit
(s[k])) cnt = cnt*
10
+ (s[k++]-
'
0
'
);
else
if
(s[k]==
'
[
'
)
{
string tem =
DFS
(s, ++k);
for
(
int
i =
0
; i < cnt; i++) ans += tem;
cnt =
0
;
}
else
if
(s[k]==
'
]
'
)
{
k++;
return
ans;
}
else
ans += s[k++];
}
return
ans;
}
string
decodeString
(string s) {
int
k =
0
;
return
DFS
(s, k);
}
};
Back
|
FazBrowse Home
|
New Git URL