# 1711. Count Good Meals ###### tags: `Leetcode` `Medium` `Two Sum` Link: https://leetcode.com/problems/count-good-meals/description/ ## 思路 典型two sum target sum是从$1$到$2^{22}$所有2的次方数 ## Code ```java= class Solution { public int countPairs(int[] deliciousness) { Map<Integer, Integer> map = new HashMap<>(); int ans = 0, mod = (int)1e9+7; for(int d:deliciousness){ int pow = 1; for(int i=0; i<22; i++){ ans = (ans+map.getOrDefault(pow-d, 0))%mod; pow*=2; } map.put(d, map.getOrDefault(d, 0)+1); } return ans; } } ```