Skip to content

Commit 2a5ee1f

Browse files
committed
650
1 parent 2dce58a commit 2a5ee1f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Aug-19-24.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def minSteps(self, n: int) -> int:
3+
def rec(l,c):
4+
if l>n:
5+
return float('inf')
6+
if l==n:
7+
return 0
8+
if (l,c) in dp:
9+
return dp[(l,c)]
10+
copyAll = 2 + rec(l+l,l)
11+
paste = 1 + rec(l+c,c)
12+
dp[(l,c)] = min(copyAll,paste)
13+
return dp[(l,c)]
14+
if n==1:
15+
return 0
16+
dp = defaultdict()
17+
return 1 + rec(1,1)

0 commit comments

Comments
 (0)