1. 程式人生 > >python leetcode 241. Different Ways to Add Parentheses

python leetcode 241. Different Ways to Add Parentheses

class Solution(object):
    def diffWaysToCompute(self, input):
        """
        :type input: str
        :rtype: List[int]
        """ 
        if input.isdigit(): return [int(input)]
        res=[]
        for i in range(len(input)):
            if input[i] in '+-*':
                L=self.
diffWaysToCompute(input[:i]) R=self.diffWaysToCompute(input[i+1:]) for r1 in L: for r2 in R: if input[i]=='*': res.append(r1*r2) elif input[i]=='+': res.
append(r1+r2) else: res.append(r1-r2) return res