Skip to content

Commit 453a4d9

Browse files
authored
Add files via upload
1 parent acfc0b5 commit 453a4d9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* @lc app=leetcode.cn id=1553 lang=cpp
3+
*
4+
* [1553] 吃掉 N 个橘子的最少天数
5+
*/
6+
#include<bits/stdc++.h>
7+
using namespace std;
8+
// @lc code=start
9+
class Solution {
10+
public:
11+
unordered_map<int,int> ans;
12+
int minDays(int n) {
13+
if(n <=1)
14+
return n;
15+
if(ans.count(n))
16+
return ans[n];
17+
else {
18+
int v = min(n % 2 + 1 + minDays(n/2),n % 3 + 1 + minDays(n/3));
19+
ans[n] = v;
20+
return v;
21+
}
22+
}
23+
};
24+
// @lc code=end
25+
26+
int mian(){
27+
Solution s = Solution();
28+
cout << s.minDays(10);
29+
return 0;
30+
}

0 commit comments

Comments
 (0)