leetcode982 Triples with Bitwise AND Equal To Zero
Posted 王宜鸣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode982 Triples with Bitwise AND Equal To Zero相关的知识,希望对你有一定的参考价值。
思路:
使用unordered_map暴力枚举。
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 class Solution 4 { 5 public: 6 int countTriplets(vector<int>& A) 7 { 8 unordered_map<int, int> mp; 9 int n = A.size(); 10 for (int i = 0; i < n; i++) 11 { 12 for (int j = 0; j < n; j++) 13 { 14 int tmp = A[i] & A[j]; 15 if (!mp.count(tmp)) mp[tmp] = 0; 16 mp[tmp]++; 17 } 18 } 19 int ans = 0; 20 for (int i = 0; i < n; i++) 21 { 22 for (auto it: mp) 23 if ((A[i] & it.first) == 0) ans += it.second; 24 25 } 26 return ans; 27 } 28 }; 29 int main() 30 { 31 int a[] = {2, 1, 3}; 32 vector<int> v(begin(a), end(a)); 33 cout << Solution().countTriplets(v) << endl; 34 return 0; 35 }
以上是关于leetcode982 Triples with Bitwise AND Equal To Zero的主要内容,如果未能解决你的问题,请参考以下文章
leetcode982. Triples with Bitwise AND Equal To Zero
UFUN 函数 UF_UI UF_DISP函数( UF_UI_select_with_class_dialog UF_DISP_set_highlight)