您的位置:首页 > Web前端

leetcode 241. Different Ways to Add Parentheses

2017-08-29 11:34 309 查看
class Solution(object):
def diffWaysToCompute(self, input):
"""
:type input: str
:rtype: List[int]
"""
""" https://discuss.leetcode.com/topic/19894/1-11-lines-python-9-lines-c """
return [a+b if c =='+' else a-b if c=='-' else a*b
for i,c in enumerate(input) if c in ('+','-','*')
for a in self.diffWaysToCompute(input[:i])
for b in self.diffWaysToCompute(input[i+1:])] or [int(input)]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息