Leetcode Note: Go - Remove One Element to Make the Array Strictly Increasing
Greatest Common Divisor of Strings - LeetCode
https://leetcode.com/problems/greatest-common-divisor-of-strings/
- Go 言語で取り組んだメモ
回答
Remove One Element to Make the Array Strictly Increasing - LeetCode
https://leetcode.com/problems/remove-one-element-to-make-the-array-strictly-increasing/
func canBeIncreasing(nums []int) bool {
chance := true
for i := 0; i < len(nums)-1; i++ {
if nums[i] >= nums[i+1] {
if chance == false {
// no chance, return false
return false
}
if i > 0 {
// we have to remove nums[i+1] if nums[i+1] ≤ nums[i-1]
if nums[i+1] <= nums[i-1] {
nums[i+1] = nums[i]
}
}
chance = false
}
}
return true
}