Created
June 16, 2018 08:47
-
-
Save MrMeison/843cb5b71fabceef361867862ddeb6d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def step(mins, n): | |
if n == 1: | |
return 0 | |
if (mins[n] != -1): | |
return mins[n] | |
result = 1 + step(mins, n-1) | |
if (n % 2 == 0): | |
result = min(result, 1 + step(mins, n // 2)) | |
if (n % 3 == 0): | |
result = min(result, 1 + step(mins, n // 3)) | |
mins[n] = result | |
return result | |
def solve (n): | |
mins = [-1] * (n+1) | |
return step(mins, n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment