Skip to content

Commit ab04d3c

Browse files
committed
Create: 0665-non-decreasing-array.go
1 parent 324cd74 commit ab04d3c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

go/0665-non-decreasing-array.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
func checkPossibility(nums []int) bool {
2+
changed := false
3+
4+
for i := 0; i < len(nums)-1; i++ {
5+
if nums[i] <= nums[i+1] {
6+
continue
7+
}
8+
if changed {
9+
return false
10+
}
11+
if i == 0 || nums[i+1] >= nums[i-1] {
12+
nums[i] = nums[i+1]
13+
} else {
14+
nums[i+1] = nums[i]
15+
}
16+
17+
changed = true
18+
}
19+
20+
return true
21+
}

0 commit comments

Comments
 (0)