Update 0941.有效的山脉数组.md
This commit is contained in:
parent
f3ec7a566d
commit
8865ed851a
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
-----------------------
|
||||
|
|
|
|||
Loading…
Reference in New Issue