Merge pull request #1537 from Cwlrin/test01

添加(0941.有效的山脉数组.md)C# 版本
This commit is contained in:
程序员Carl
2022-07-27 09:11:25 +08:00
committed by GitHub

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