Advertisement
nikunjsoni

1711

Apr 20th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int countPairs(vector<int>& deliciousness) {
  4.         unordered_map<int, int> counter;
  5.        
  6.         long long ans=0, mod=int(1e9)+7;
  7.         for(int d: deliciousness){
  8.             for(int i=1, sum=1; i<=22; i++, sum*=2)
  9.                 if(counter.count(sum-d))
  10.                     ans = (ans + counter[sum-d])%mod;
  11.             counter[d]++;
  12.         }
  13.         return ans;
  14.     }
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement