We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 26692cb commit 19e323cCopy full SHA for 19e323c
Reverse Polish Notation/program.cpp
@@ -0,0 +1,34 @@
1
+class Solution {
2
+public:
3
+ int evalRPN(vector<string>& tokens)
4
+ {
5
+ stack<long>stk;
6
+ for(int i=0;i<tokens.size();i++)
7
8
+ if(tokens[i]!="+" && tokens[i]!="/" && tokens[i]!="*" && tokens[i]!="-")
9
10
+ long t=stoi(tokens[i]);
11
+ stk.push(t);
12
+ }
13
+ else
14
15
+ long a=stk.top();
16
+ stk.pop();
17
+ long b=stk.top();
18
19
+ string ch=tokens[i];
20
+ long c=0;
21
+ if(ch=="+")
22
+ c=b+a;
23
+ if(ch=="-")
24
+ c=b-a;
25
+ if(ch=="*")
26
+ c=b*a;
27
+ if(ch=="/")
28
+ c=b/a;
29
+ stk.push(c);
30
31
32
+ return int(stk.top());
33
34
+};
0 commit comments