forked from onlybooks/python-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path84-1.py
More file actions
23 lines (18 loc) · 683 Bytes
/
84-1.py
File metadata and controls
23 lines (18 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import List
class Solution:
def diffWaysToCompute(self, input: str) -> List[int]:
def compute(left, right, op):
results = []
for l in left:
for r in right:
results.append(eval(str(l) + op + str(r)))
return results
if input.isdigit():
return [int(input)]
results = []
for index, value in enumerate(input):
if value in "-+*":
left = self.diffWaysToCompute(input[:index])
right = self.diffWaysToCompute(input[index + 1:])
results.extend(compute(left, right, value))
return results