Skip to content

Commit c31d86c

Browse files
1711. Count Good Meals
1 parent dbbde65 commit c31d86c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

CountGoodMeals_1711.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
~ Author : https://leetcode.com/tridib_2003/
3+
~ Problem : 1711. Count Good Meals
4+
~ Link : https://leetcode.com/problems/count-good-meals/
5+
*/
6+
7+
class Solution {
8+
public:
9+
#define MOD 1000000007
10+
11+
int countPairs(vector<int>& deliciousness) {
12+
13+
unordered_map<int, int> freq;
14+
15+
int ans = 0;
16+
17+
for (int i : deliciousness) {
18+
19+
for (int pw = 1; pw <= (1 << 22); pw *= 2) {
20+
21+
if (freq[pw - i])
22+
ans = (ans + freq[pw - i]) % MOD;
23+
}
24+
25+
++freq[i];
26+
}
27+
28+
return ans;
29+
}
30+
};

0 commit comments

Comments
 (0)