Movatterモバイル変換


[0]ホーム

URL:


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

Commit2dcab61

Browse files
author
Sathish Babu
committed
✨ Added solution to 941
1 parent78fa867 commit2dcab61

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

‎src/0941.Valid-Mountain-Array/README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,35 @@
55
66
##Description
77

8+
Given an array A of integers, return true if and only if it is a valid mountain array.
9+
10+
Recall that A is a mountain array if and only if:
11+
12+
A.length >= 3
13+
There exists some i with 0 < i < A.length - 1 such that:
14+
A[0] < A[1] < ... A[i-1] < A[i]
15+
A[i] > A[i+1] > ... > A[A.length - 1]
16+
17+
818
**Example 1:**
919

1020
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
21+
Input: [2,1]
22+
Output: false
23+
```
24+
25+
**Example 2:**
26+
27+
```
28+
Input: [3,5,5]
29+
Output: false
30+
```
31+
32+
**Example 3:**
33+
34+
```
35+
Input: [0,3,2,1]
36+
Output: true
1337
```
1438

1539
##题意
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package Solution
22

3-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(A []int)bool {
4+
n:=len(A)
5+
ifn<=2 {
6+
returnfalse
7+
}
8+
pass:=0
9+
for ;pass+1<n&&A[pass]<A[pass+1];pass++ {
10+
}
11+
ifpass==0||pass==n-1 {
12+
returnfalse
13+
}
14+
for ;pass+1<n&&A[pass]>A[pass+1];pass++ {
15+
}
16+
returnpass==n-1
517
}

‎src/0941.Valid-Mountain-Array/Solution_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ func TestSolution(t *testing.T) {
1010
//测试用例
1111
cases:= []struct {
1212
namestring
13-
inputsbool
13+
inputs[]int
1414
expectbool
1515
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
16+
{"TestCase", []int{2,1},false},
17+
{"TestCase", []int{3,5,5},false},
18+
{"TestCase", []int{3,4,5},false},
19+
{"TestCase", []int{0,3,2,1},true},
1920
}
2021

2122
//开始测试

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp