Day 1: use set for faster lookup
This commit is contained in:
parent
2f3b1401f7
commit
de9bb292a3
@ -7,9 +7,9 @@ with open('input.txt', 'r') as f:
|
||||
in_list = [x.strip() for x in in_list]
|
||||
|
||||
in_list = [int(x) for x in in_list]
|
||||
print(in_list)
|
||||
# print(in_list)
|
||||
|
||||
freq = []
|
||||
freq = set()
|
||||
|
||||
res = 0
|
||||
i = 0
|
||||
@ -18,9 +18,10 @@ while True:
|
||||
i = 0
|
||||
res += in_list[i]
|
||||
|
||||
freq.append(res)
|
||||
if len(freq) != len(set(freq)):
|
||||
if res in freq:
|
||||
break
|
||||
|
||||
freq.add(res)
|
||||
i += 1
|
||||
|
||||
print(res)
|
||||
|
Loading…
Reference in New Issue
Block a user