Merge pull request #1729 from Jack-Zhang-1314/patch-3

update 0150.逆波兰表达式求值.md about rust
This commit is contained in:
程序员Carl
2022-11-15 11:53:18 +08:00
committed by GitHub

View File

@ -420,6 +420,41 @@ object Solution {
}
```
rust:
```rust
impl Solution {
pub fn eval_rpn(tokens: Vec<String>) -> i32 {
let mut stack = vec![];
for token in tokens.into_iter() {
match token.as_str() {
"+" => {
let a = stack.pop().unwrap();
*stack.last_mut().unwrap() += a;
}
"-" => {
let a = stack.pop().unwrap();
*stack.last_mut().unwrap() -= a;
}
"*" => {
let a = stack.pop().unwrap();
*stack.last_mut().unwrap() *= a;
}
"/" => {
let a = stack.pop().unwrap();
*stack.last_mut().unwrap() /= a;
}
_ => {
stack.push(token.parse::<i32>().unwrap());
}
}
}
stack.pop().unwrap()
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>