This is a programmers stack/queue issue.
count = 0
for i in range(len(left_days)):
largest = left_days[0]
if(largest >= left_days[i]):
count += 1
if(i==len(left_days)-1):
answer.append(count)
else:
pass
else:
if(i==len(left_days)-1):
answer.append(count)
answer.append(1)
break
else:
answer.append(count)
del left_days[:i]
count=0
i = 0
Traceback (most recent call last):
File "/solution_test.py", line 18, in test
actual0 = solution(p0_0,p0_1)
File "/solution.py", line 24, in solution
if(largest >= left_days[i]):
IndexError: list index out of range
It comes out like this, but some examples are solved, and the rest have that error. No matter how hard I try, I don't know why it smells... The cord is dirty, but I'd appreciate it if you could take a look.
python stack queue
Maybe the Len value is the total size The index starts from 0 instead of 1 Shouldn't you do -1 for the range?
for i in range(len(left_days)): -> for i in range(len(left_days)-1):
© 2024 OneMinuteCode. All rights reserved.