1909. 删除一个元素使数组严格递增

https://leetcode-cn.com/problems/remove-one-element-to-make-the-array-strictly-increasing/

解法一:暴力

class Solution:
    def canBeIncreasing(self, a: List[int]) -> bool:
        n = len(a)
        b = []
        #尝试将a的每个位置去掉,得到剩下数组b,看是否递增
        
        for i in range(n):
            b = []
            
            for j in range(n):
                if j == i: 
                    continue
                b.append(a[j])
            ok = True
            for j in range(1, n-1):
                if b[j] <= b[j-1]:
                    ok = False
            if ok:
                return True #找到一个符合的b就返回真
        return False    #一个都找不到

最后更新于