-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAY9
More file actions
31 lines (26 loc) · 881 Bytes
/
DAY9
File metadata and controls
31 lines (26 loc) · 881 Bytes
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 {
long resolves(int a, int b, char Operator){
if(Operator == '+') return a + b;
else if(Operator == '-') return a - b;
else if(Operator == '*') return (long)a*b;
return a/b;
}
public:
int evalRPN(vector<string>& tokens) {
stack<long> Stack;
int n = tokens.size();
for(int i = 0; i < n; i++){
if(tokens[i].size() == 1 and tokens[i][0] < 48){
long integer2 = Stack.top();
Stack.pop();
long integer1 = Stack.top();
Stack.pop();
string Operator = tokens[i];
long resolvedAns = resolves(integer1, integer2 , Operator[0]);
Stack.push(resolvedAns);
}else
Stack.push(stol(tokens[i]));
}
return Stack.top();
}
};