Solve almostIncreasingSequence (Codefights)

后端 未结 15 1254
谎友^
谎友^ 2020-12-08 07:35

Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array.

15条回答
  •  孤城傲影
    2020-12-08 08:10

    I'm still working on mine. Wrote it like this but I can't pass the last 3 hidden tests.

    def almostIncreasingSequence(sequence):
    
    boolMe = 0
    checkRep = 0
    
    for x in range(0, len(sequence)-1):
    
        if sequence[x]>sequence[x+1]:
            boolMe = boolMe + 1
            if (x!=0) & (x!=(len(sequence)-2)):
                if sequence[x-1]>sequence[x+2]:
                    boolMe = boolMe + 1
        if sequence.count(sequence[x])>1:
            checkRep = checkRep + 1
    
        if (boolMe > 1) | (checkRep > 2):    
            return False
    return True
    

提交回复
热议问题