From 30685b815cc8787fd84d760045a4e26456a51ef7 Mon Sep 17 00:00:00 2001 From: "junjie2.luo" Date: Thu, 10 Oct 2024 17:19:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=200941.=E6=9C=89=E6=95=88=E7=9A=84?= =?UTF-8?q?=E5=B1=B1=E8=84=89=E6=95=B0=E7=BB=84,=E6=96=B0=E5=A2=9Erust?= =?UTF-8?q?=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0941.有效的山脉数组.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/problems/0941.有效的山脉数组.md b/problems/0941.有效的山脉数组.md index 9f63f441..77167df0 100644 --- a/problems/0941.有效的山脉数组.md +++ b/problems/0941.有效的山脉数组.md @@ -196,7 +196,22 @@ public class Solution { } ``` - +### Rust +```rust +impl Solution { + pub fn valid_mountain_array(arr: Vec) -> 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 + } +} +```