forked from onlybooks/python-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.py
More file actions
25 lines (23 loc) · 643 Bytes
/
2.py
File metadata and controls
25 lines (23 loc) · 643 Bytes
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
def solution(dartResult: str) -> int:
nums = [0]
for s in dartResult:
if s == 'S':
nums[-1] **= 1
nums.append(0)
elif s == 'D':
nums[-1] **= 2
nums.append(0)
elif s == 'T':
nums[-1] **= 3
nums.append(0)
elif s == '*':
# 이전 값, 그 이전 값 모두 두 배 처리
nums[-2] *= 2
if len(nums) > 2:
nums[-3] *= 2
elif s == '#':
nums[-2] *= -1
else:
# 자릿수 올림
nums[-1] = nums[-1] * 10 + int(s)
return sum(nums)