Skip to content

Commit 30685b8

Browse files
author
junjie2.luo
committed
feat: 0941.有效的山脉数组,新增rust解法
1 parent e43323b commit 30685b8

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

problems/0941.有效的山脉数组.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,22 @@ public class Solution {
196196
}
197197
```
198198

199-
199+
### Rust
200+
```rust
201+
impl Solution {
202+
pub fn valid_mountain_array(arr: Vec<i32>) -> bool {
203+
let mut i = 0;
204+
let mut j = arr.len() - 1;
205+
while i < arr.len() - 1 && arr[i] < arr[i + 1] {
206+
i += 1;
207+
}
208+
while j > 0 && arr[j] < arr[j - 1] {
209+
j -= 1;
210+
}
211+
i > 0 && j < arr.len() - 1 && i == j
212+
}
213+
}
214+
```
200215

201216
<p align="center">
202217
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
 (0)