File tree 2 files changed +42
-0
lines changed
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 27
27
2 . [ Longest Mountain in Array] ( https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3533/ ) ➡️ [ CPP Solution] ( Week3/longestMountain.cpp )
28
28
3 . [ Mirror Reflection] ( https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3534/ ) ➡️ [ CPP Solution] ( Week3/mirrorReflection.cpp )
29
29
4 . [ Merge Intervals] ( https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3535/ ) ➡️ [ CPP Solution] ( Week3/merge.cpp )
30
+ 5 . [ Decode String] ( https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/566/week-3-november-15th-november-21st/3536/ ) ➡️ [ CPP Solution] ( Week3/decodeString.cpp )
30
31
31
32
## Week 4 🚧
32
33
Coming soon...
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ string decodeString (string s) {
4
+ stack<int > numStack;
5
+ stack<string> strStack;
6
+
7
+ string str = " " ;
8
+ int num = 0 ;
9
+
10
+ for (char c: s) {
11
+
12
+ if (isdigit (c)) {
13
+ num = num * 10 + (c - ' 0' );
14
+ } else if (c == ' [' ) {
15
+ strStack.push (str);
16
+ str = " " ;
17
+
18
+ numStack.push (num);
19
+ num = 0 ;
20
+ } else if (c == ' ]' ) {
21
+ string temp = str;
22
+
23
+ str = strStack.top ();
24
+ strStack.pop ();
25
+
26
+ int count = numStack.top ();
27
+ numStack.pop ();
28
+
29
+ while (count-- > 0 ) {
30
+ str.append (temp);
31
+ }
32
+
33
+ } else {
34
+ str += c;
35
+ }
36
+
37
+ }
38
+
39
+ return str;
40
+ }
41
+ };
You can’t perform that action at this time.
0 commit comments