Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
1909_Remove_One_Element_to_Make_the_Array_Strictly_Increasing
In a brute-force way.
  • Loading branch information
LONGNEW authored Sep 23, 2022
commit fcd9fcec35cb2309a0414a140b4c3325a5103d67
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Solution:
def canBeIncreasing(self, nums: List[int]) -> bool:
# bruteforcing the whole idxes.
canBe = [0] * len(nums)

# choosing the idx that will be removed.
for bannedIdx in range(len(nums)):
Flag = 1

# if the bannedIdx is 0 than the startIdx will be 2.
# when bannedIdx is 0, idx 2 is the first element that has a previous element.
# In other cases, idx 1 is the one.
for i in range(1 if bannedIdx != 0 else 2, len(nums)):
# if i is bannedIdx than just skip it.
if i == bannedIdx:
continue

# if the previous element is banned.
# compare [i] with [i - 2]
if i - 1 == bannedIdx:
if nums[i] <= nums[i - 2]:
Flag = 0
break
continue

# compare [i] with [i - 1]
if nums[i] <= nums[i - 1]:
Flag = 0
break

# end of loop we will get Flag that has a 0 or 1 value.
canBe[bannedIdx] = Flag

if sum(canBe) > 0:
return True
return False