File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
1501-2000/1815-Maximum-Number-of-Groups-Getting-Fresh-Donuts/cpp-1815 Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 1
1
// / Source : https://leetcode.com/problems/maximum-number-of-groups-getting-fresh-donuts/
2
2
// / Author : liuyubobobo
3
3
// / Time : 2020-06-11
4
+ // / Updaetd: 2023-01-21
4
5
5
6
#include < iostream>
6
7
#include < vector>
10
11
using namespace std ;
11
12
12
13
13
- // / Memory Search - vector as key
14
+ // / Memory Search
14
15
// / Time Complexity: O(2^n)
15
16
// / Space Complexity: O(2^n)
16
17
class Solution {
@@ -23,15 +24,18 @@ class Solution {
23
24
int res = f[0 ];
24
25
f[0 ] = 0 ;
25
26
26
- map<vector< int > , int > dp;
27
+ map<long long , int > dp;
27
28
res += dfs (f, batchSize, dp);
28
29
return res;
29
30
}
30
31
31
32
private:
32
- int dfs (vector<int >& f, int k, map<vector< int > , int >& dp){
33
+ int dfs (vector<int >& f, int k, map<long long , int >& dp){
33
34
34
- auto iter = dp.find (f);
35
+ long long h = 0 ;
36
+ for (int e: f) h = h * 10ll + e;
37
+
38
+ auto iter = dp.find (h);
35
39
if (iter != dp.end ()) return iter->second ;
36
40
37
41
int pre = f[0 ];
@@ -44,7 +48,7 @@ class Solution {
44
48
f[0 ] = pre;
45
49
f[i] ++;
46
50
}
47
- return dp[f ] = res;
51
+ return dp[h ] = res;
48
52
}
49
53
};
50
54
You can’t perform that action at this time.
0 commit comments