241. Different Ways to Add Parentheses
![17368230-b6bbd06f402509c7.png](https://i-blog.csdnimg.cn/blog_migrate/c3195cf7a6c75912bae3e9d42f010659.webp?x-image-process=image/format,png)
241. Different Ways to Add Parentheses
class Solution(object):
def diffWaysToCompute(self, input):
"""
:type input: str
:rtype: List[int]
"""
res = []
for i, v in enumerate(input):
if v in "+-*":
for l1 in self.diffWaysToCompute(input[:i]):
for l2 in self.diffWaysToCompute(input[i+1:]):
if v == '+':
res.append(l1 + l2)
elif v == "-":
res.append(l1 - l2)
else:
res.append(l1 * l2)
if len(res) == 0:
return [int(input)]
return res