Class Solution
java.lang.Object
g1701_1800.s1711_count_good_meals.Solution
1711 - Count Good Meals.<p>Medium</p>
<p>A <strong>good meal</strong> is a meal that contains <strong>exactly two different food items</strong> with a sum of deliciousness equal to a power of two.</p>
<p>You can pick <strong>any</strong> two different foods to make a good meal.</p>
<p>Given an array of integers <code>deliciousness</code> where <code>deliciousness[i]</code> is the deliciousness of the <code>i<sup>th</sup></code> item of food, return <em>the number of different <strong>good meals</strong> you can make from this list modulo</em> <code>10<sup>9</sup> + 7</code>.</p>
<p>Note that items with different indices are considered different even if they have the same deliciousness value.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> deliciousness = [1,3,5,7,9]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> The good meals are (1,3), (1,7), (3,5) and, (7,9). Their respective sums are 4, 8, 8, and 16, all of which are powers of 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> deliciousness = [1,1,1,3,3,3,7]</p>
<p><strong>Output:</strong> 15</p>
<p><strong>Explanation:</strong> The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= deliciousness.length <= 10<sup>5</sup></code></li>
<li><code>0 <= deliciousness[i] <= 2<sup>20</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
countPairs
public int countPairs(int[] d)
-