We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a1fa282 commit e0d1327Copy full SHA for e0d1327
leetcode/cpp/Stacks/682.cpp
@@ -0,0 +1,33 @@
1
+//Problem 682 : Baseball Game(using stack)
2
+
3
+class Solution {
4
+public:
5
+ int calPoints(vector<string>& ops)
6
+ {
7
+ int result = 0;
8
+ stack <int> score;
9
+ for (auto x : ops)
10
11
+ if (x == "C" && !score.empty())
12
+ score.pop();
13
+ else if(x == "D" && !score.empty())
14
+ score.push(2*score.top());
15
+ else if(x == "+" && !score.empty())
16
17
+ int top1 = score.top();
18
19
+ int top2 = score.top();
20
+ score.push(top1);
21
+ score.push((top1+top2));
22
+ }
23
+ else
24
+ score.push(stoi(x)); // convert from string to int then push on stack
25
26
+ while(!score.empty())
27
28
+ result += score.top();
29
30
31
+ return result;
32
33
+};
0 commit comments