-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart_one.py
39 lines (27 loc) · 879 Bytes
/
part_one.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import override
from infrastructure.solutions.base import Solution
class Year2020Day1Part1Solution(Solution):
TARGET_SUM = 2020
@classmethod
@override
def parse_input(cls, text_input: str) -> dict[str, list[int]]:
expenses = []
for record in text_input.split('\n'):
expenses.append(int(record))
return {'expenses': expenses}
@classmethod
@override
def solve(cls, expenses: list[int]) -> int:
"""
Time: O(n)
Space: O(n)
Where n - expenses length
"""
seen_records = set()
for record in expenses:
if cls.TARGET_SUM - record in seen_records:
return record * (cls.TARGET_SUM - record)
seen_records.add(record)
return -1
if __name__ == '__main__':
print(Year2020Day1Part1Solution.main())