Skip to content

Commit 06feda5

Browse files
Merge pull request #3442 from Tetsuya3850/patch-3
2 parents a940e8f + 8ca4a14 commit 06feda5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int minDays(int n) {
3+
Map<Integer, Integer> dp = new HashMap<>();
4+
dp.put(0, 0);
5+
dp.put(1, 1);
6+
return dfs(n, dp);
7+
}
8+
9+
private int dfs(int n, Map<Integer, Integer> dp) {
10+
if (dp.containsKey(n)) {
11+
return dp.get(n);
12+
}
13+
int optionOne = 1 + n % 2 + dfs(n / 2, dp);
14+
int optionTwo = 1 + n % 3 + dfs(n / 3, dp);
15+
dp.put(n, Math.min(optionOne, optionTwo));
16+
return dp.get(n);
17+
}
18+
}

0 commit comments

Comments
 (0)