Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6d82627

Browse files
添加(0941.有效的山脉数组.md):增加typescript版本
1 parent b78e750 commit 6d82627

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,26 @@ var validMountainArray = function(arr) {
157157
};
158158
```
159159

160+
## TypeScript
161+
162+
```typescript
163+
function validMountainArray(arr: number[]): boolean {
164+
const length: number = arr.length;
165+
if (length < 3) return false;
166+
let left: number = 0,
167+
right: number = length - 1;
168+
while (left < (length - 1) && arr[left] < arr[left + 1]) {
169+
left++;
170+
}
171+
while (right > 0 && arr[right] < arr[right - 1]) {
172+
right--;
173+
}
174+
if (left === right && left !== 0 && right !== length - 1)
175+
return true;
176+
return false;
177+
};
178+
```
179+
160180

161181

162182

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /