fbaquant / LeetCode

1 stars 0 forks source link

Remove One Element to Make the Array Strictly Increasing #120

Open juneharold opened 3 months ago

juneharold commented 3 months ago

Brute force works well

class Solution:
    def canBeIncreasing(self, nums: List[int]) -> bool:
        remove = False
        for i in range(len(nums)-1):
            if nums[i]<nums[i+1]:
                pass
            else:
                if remove:
                    return False
                if nums[i-1]>=nums[i+1] and i>0:
                    nums[i+1] = nums[i]
                remove = True
        return True