We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent acfc0b5 commit 453a4d9Copy full SHA for 453a4d9
leetcode/1553.吃掉-n-个橘子的最少天数.cpp
@@ -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