mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
@ -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