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.
2 parents 4e78470 + c8f003a commit 397d338Copy full SHA for 397d338
dart/0150-evaluate-reverse-polish-notation.dart
@@ -0,0 +1,28 @@
1
+class Solution {
2
+ int evalRPN(List<String> tokens) {
3
+ var stack = [];
4
+ for (var i = 0; i < tokens.length; i++) {
5
+ var char = tokens[i];
6
+ if (char == '+') {
7
+ var a = stack.removeLast();
8
+ var b = stack.removeLast();
9
+ stack.add(a + b);
10
+ } else if (char == '-') {
11
12
13
+ stack.add(b - a);
14
+ } else if (char == '*') {
15
16
17
+ stack.add(a * b);
18
+ } else if (char == '/') {
19
20
21
+ stack.add(b ~/ a);
22
+ } else {
23
+ stack.add(int.parse(char));
24
+ }
25
26
+ return stack.first;
27
28
+}
0 commit comments