mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 16:36:41 +08:00
18 lines
275 B
Go
18 lines
275 B
Go
package leetcode
|
|
|
|
func checkPossibility(nums []int) bool {
|
|
count := 0
|
|
for i := 0; i < len(nums)-1; i++ {
|
|
if nums[i] > nums[i+1] {
|
|
count++
|
|
if count > 1 {
|
|
return false
|
|
}
|
|
if i > 0 && nums[i+1] < nums[i-1] {
|
|
nums[i+1] = nums[i]
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|