Update 0941.有效的山脉数组.md

This commit is contained in:
桜小路七葉
2022-07-22 15:36:23 +08:00
committed by GitHub
parent f3ec7a566d
commit 8865ed851a

View File

@ -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;
}
}
```
-----------------------