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 5a20356

Browse files
committed
Update: Monotonic Array
1 parent de52857 commit 5a20356

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package monotonic_array
22

33
func isMonotonic(A []int) bool {
4-
t, f := 0, 0
4+
increasing, decreasing := true, true
55
for i, v := range A[1:] {
66
if v > A[i] {
7-
t++
7+
decreasing=false
88
} else if v < A[i] {
9-
f++
9+
increasing=false
1010
}
1111
}
12-
return t==0|| f==0
12+
return increasing|| decreasing
1313
}

0 commit comments

Comments
(0)

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