mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
feat: 0941.有效的山脉数组,新增rust解法
This commit is contained in:
@ -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">
|
||||||
|
Reference in New Issue
Block a user