File tree 2 files changed +47
-3
lines changed
2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change 16
16
17
17
### Problems Solved
18
18
19
- | Total | 59 |
19
+ | Total | 60 |
20
20
| :---:| :---:|
21
21
22
22
#### Search By Topic
38
38
| Math & Geometry | 4 |
39
39
| Priority Queue | 3 |
40
40
| Sliding Window | 2 |
41
- | Stack | 2 |
41
+ | Stack | 3 |
42
42
| Tries | 0 |
43
43
| Two Pointers | 6 |
44
44
47
47
| Difficulty | Number |
48
48
| :---| ---:|
49
49
| Easy | 48 |
50
- | Medium | 11 |
50
+ | Medium | 12 |
51
51
| Hard | 0 |
52
52
53
53
## Milestones
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Problem: 150
3
+ * Name: Evaluate Reverse Polish Notation
4
+ * Difficulty: Medium
5
+ * Topic: Stack
6
+ * Link: https://leetcode.com/problems/evaluate-reverse-polish-notation/
7
+ */
8
+
9
+ #include < bits/stdc++.h>
10
+ using namespace std ;
11
+
12
+ // Stack Structure
13
+ // Time Complexity: O(n)
14
+ // Space Complexity: O(n)
15
+ int evalRPN (vector<string>& tokens) {
16
+ stack<int > values;
17
+
18
+ for (const string& s : tokens) {
19
+ if (s == " +" ){
20
+ int a = values.top (); values.pop ();
21
+ int b = values.top (); values.pop ();
22
+ values.push (b + a);
23
+ }
24
+ else if (s == " -" ){
25
+ int a = values.top (); values.pop ();
26
+ int b = values.top (); values.pop ();
27
+ values.push (b - a);
28
+ }
29
+ else if (s == " *" ){
30
+ int a = values.top (); values.pop ();
31
+ int b = values.top (); values.pop ();
32
+ values.push (b * a);
33
+ }
34
+ else if (s == " /" ){
35
+ int a = values.top (); values.pop ();
36
+ int b = values.top (); values.pop ();
37
+ values.push (b / a);
38
+ }
39
+ else {
40
+ values.push (stoi (s));
41
+ }
42
+ }
43
+ return values.top ();
44
+ }
You can’t perform that action at this time.
0 commit comments