Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aba0543

Browse files
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
Lines changed: 14 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /