Skip to content

Commit 113feb7

Browse files
authored
Merge pull request #3635 from abdulrafayl226825/rafay
Created 0241-Different Ways To Add Prantheses
2 parents 9163041 + 2f62b00 commit 113feb7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def diffWaysToCompute(self, s: str) -> List[int]:
3+
def f(s):
4+
res = []
5+
for i, c in enumerate(s):
6+
if c in '+-*':
7+
for l in f(s[:i]):
8+
for r in f(s[i + 1:]):
9+
res.append(eval(f'{l}{c}{r}'))
10+
11+
return res or [int(s)]
12+
return f(s)

0 commit comments

Comments
 (0)