Em đang học python trên CF thì gặp bài này :
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.
(Cho một dãy số bất kì, kiểm tra xem nếu xóa 1 số thuộc dãy số đó thì ta có thu được 1 dãy tăng dần không. Yêu cầu các số trong dãy thu được sau khi xóa phải khác nhau)
Sau đây là code của em :
def phantudau(sequence):
for i in range(len(sequence)-1):
if sequence[i]>sequence[i+1]:
return i
return -1
def almostIncreasingSequence(sequence):
j=phantudau(sequence)
if j != -1:
del sequence[j]
if phantudau(sequence) == -1:
return True
else:
return False
else:
return True
Em đã test các key test nhưng tất cả chỉ trả về True , ai có thể giúp em với ạ