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 b489cb6 commit 0146595Copy full SHA for 0146595
problems/0150.逆波兰表达式求值.md
@@ -162,6 +162,40 @@ class Solution {
162
}
163
```
164
165
+```Java
166
+// Switch Case 写法,更简洁一些
167
+class Solution {
168
+ public int evalRPN(String[] tokens) {
169
+ Stack<Integer> stk = new Stack<>();
170
+ for (String token : tokens) {
171
+
172
+ // 运算符Operator + - * /
173
+ if ("+-*/".contains(token)) {
174
+ int a = stk.pop();
175
+ int b = stk.pop();
176
+ switch (token) {
177
+ case "+":
178
+ stk.push(a + b);
179
+ break;
180
+ case "-":
181
+ stk.push(b - a);
182
183
+ case "*":
184
+ stk.push(a * b);
185
186
+ case "/":
187
+ stk.push(b / a);
188
189
+ }
190
+ } else {
191
+ stk.push(Integer.parseInt(token));
192
193
194
+ return stk.pop();
195
196
+}
197
+```
198
199
### Python3:
200
201
```python
0 commit comments