mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
Update 0941.有效的山脉数组.md
This commit is contained in:
@ -177,7 +177,24 @@ function validMountainArray(arr: number[]): boolean {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## C#
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public class Solution {
|
||||||
|
public bool ValidMountainArray(int[] arr) {
|
||||||
|
if (arr.Length < 3) return false;
|
||||||
|
|
||||||
|
int left = 0;
|
||||||
|
int right = arr.Length - 1;
|
||||||
|
|
||||||
|
while (left + 1< arr.Length && arr[left] < arr[left + 1]) left ++;
|
||||||
|
while (right > 0 && arr[right] < arr[right - 1]) right --;
|
||||||
|
if (left == right && left != 0 && right != arr.Length - 1) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user