Skip to content

Commit 8865ed8

Browse files
authored
Update 0941.有效的山脉数组.md
1 parent f3ec7a5 commit 8865ed8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

problems/0941.有效的山脉数组.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,24 @@ function validMountainArray(arr: number[]): boolean {
177177
};
178178
```
179179

180+
## C#
180181

182+
```csharp
183+
public class Solution {
184+
public bool ValidMountainArray(int[] arr) {
185+
if (arr.Length < 3) return false;
186+
187+
int left = 0;
188+
int right = arr.Length - 1;
189+
190+
while (left + 1< arr.Length && arr[left] < arr[left + 1]) left ++;
191+
while (right > 0 && arr[right] < arr[right - 1]) right --;
192+
if (left == right && left != 0 && right != arr.Length - 1) return true;
193+
194+
return false;
195+
}
196+
}
197+
```
181198

182199

183200
-----------------------

0 commit comments

Comments
 (0)