1909. Remove One Element to Make the Array Strictly Increasing
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 29% Topics: Array
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def canBeIncreasing(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
deleted = False
for i in xrange(1, len(nums)):
if nums[i] > nums[i-1]:
continue
if deleted:
return False
deleted = True
if i >= 2 and nums[i-2] > nums[i]: # delete nums[i] or nums[i-1]
nums[i] = nums[i-1]
return True
Solution from kamyu104/LeetCode-Solutions · MIT