File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1- # 1,493 LeetCode solutions in JavaScript
1+ # 1,494 LeetCode solutions in JavaScript
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
131813181706|[ Where Will the Ball Fall] ( ./solutions/1706-where-will-the-ball-fall.js ) |Medium|
131913191707|[ Maximum XOR With an Element From Array] ( ./solutions/1707-maximum-xor-with-an-element-from-array.js ) |Hard|
132013201710|[ Maximum Units on a Truck] ( ./solutions/1710-maximum-units-on-a-truck.js ) |Easy|
1321+ 1711|[ Count Good Meals] ( ./solutions/1711-count-good-meals.js ) |Medium|
132113221716|[ Calculate Money in Leetcode Bank] ( ./solutions/1716-calculate-money-in-leetcode-bank.js ) |Easy|
132213231718|[ Construct the Lexicographically Largest Valid Sequence] ( ./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js ) |Medium|
132313241726|[ Tuple with Same Product] ( ./solutions/1726-tuple-with-same-product.js ) |Medium|
Original file line number Diff line number Diff line change 1+ /**
2+ * 1711. Count Good Meals
3+ * https://leetcode.com/problems/count-good-meals/
4+ * Difficulty: Medium
5+ *
6+ * A good meal is a meal that contains exactly two different food items with a sum of deliciousness
7+ * equal to a power of two.
8+ *
9+ * You can pick any two different foods to make a good meal.
10+ *
11+ * Given an array of integers deliciousness where deliciousness[i] is the deliciousness of the
12+ * ith item of food, return the number of different good meals you can make from this list
13+ * modulo 109 + 7.
14+ *
15+ * Note that items with different indices are considered different even if they have the same
16+ * deliciousness value.
17+ */
18+
19+ /**
20+ * @param {number[] } deliciousness
21+ * @return {number }
22+ */
23+ var countPairs = function ( deliciousness ) {
24+ const MOD = 1e9 + 7 ;
25+ const frequency = new Map ( ) ;
26+ let result = 0 ;
27+
28+ for ( const value of deliciousness ) {
29+ for ( let power = 1 ; power <= 1 << 21 ; power <<= 1 ) {
30+ const complement = power - value ;
31+ if ( frequency . has ( complement ) ) {
32+ result = ( result + frequency . get ( complement ) ) % MOD ;
33+ }
34+ }
35+ frequency . set ( value , ( frequency . get ( value ) || 0 ) + 1 ) ;
36+ }
37+
38+ return result ;
39+ } ;
You can’t perform that action at this time.
0 commit comments