Skip to content

Commit aba0543

Browse files
committed
Time: 216 ms (34.17%), Space: 16.4 MB (88.15%) - LeetHub
1 parent 601469b commit aba0543

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def minSteps(self, n: int) -> int:
3+
if n == 1:
4+
return 0
5+
6+
dp = [0] * (n + 1)
7+
8+
for i in range(2, n + 1):
9+
dp[i] = i # maximum operations needed (all pastes)
10+
for j in range(1, i // 2 + 1):
11+
if i % j == 0:
12+
dp[i] = min(dp[i], dp[j] + (i // j))
13+
14+
return dp[n]

0 commit comments

Comments
 (0)