-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpart_two.py
39 lines (27 loc) · 924 Bytes
/
part_two.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 Year2015Day8Part2Solution(Solution):
@classmethod
@override
def parse_input(cls, text_input: str) -> dict[str, list[str]]:
strings = []
for line in text_input.split('\n'):
strings.append(line)
return {'strings': strings}
@classmethod
@override
def solve(cls, strings: list[str]) -> int:
"""
Time: O(n*m)
Space: O(1)
Where n - numbers of strings
m - maximum string length
"""
characters = 0
for string in strings:
characters += 2 # Quotes at the beginning and end
characters += string.count(r'"') # Nested quotes
characters += string.count('\\') # Escape chars
return characters
if __name__ == '__main__':
print(Year2015Day8Part2Solution.main())