update 0020.有效的括号.md about rust
This commit is contained in:
parent
a4d54dd073
commit
2e5466bdce
|
|
@ -493,6 +493,33 @@ object Solution {
|
|||
}
|
||||
```
|
||||
|
||||
rust:
|
||||
|
||||
```rust
|
||||
impl Solution {
|
||||
pub fn is_valid(s: String) -> bool {
|
||||
if s.len() % 2 == 1 {
|
||||
return false;
|
||||
}
|
||||
let mut stack = vec![];
|
||||
let mut chars: Vec<char> = s.chars().collect();
|
||||
while let Some(s) = chars.pop() {
|
||||
match s {
|
||||
')' => stack.push('('),
|
||||
']' => stack.push('['),
|
||||
'}' => stack.push('{'),
|
||||
_ => {
|
||||
if stack.is_empty() || stack.pop().unwrap() != s {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stack.is_empty()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<p align="center">
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue