feat: 0941.有效的山脉数组,新增rust解法

This commit is contained in:
junjie2.luo
2024-10-10 17:19:43 +08:00
parent e43323b1e1
commit 30685b815c

View File

@ -196,7 +196,22 @@ public class Solution {
} }
``` ```
### Rust
```rust
impl Solution {
pub fn valid_mountain_array(arr: Vec<i32>) -> bool {
let mut i = 0;
let mut j = arr.len() - 1;
while i < arr.len() - 1 && arr[i] < arr[i + 1] {
i += 1;
}
while j > 0 && arr[j] < arr[j - 1] {
j -= 1;
}
i > 0 && j < arr.len() - 1 && i == j
}
}
```
<p align="center"> <p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">