leetcode-982-Triples with Bitwise AND Equal To Zero
问题
Given an array of integers A
, find the number of triples of indices (i, j, k) such that:
0 <= i < A.length
0 <= j < A.length
0 <= k < A.length
A[i] & A[j] & A[k] == 0
, where&
represents the bitwise-AND operator.
Example 1:
1 | Input: [2,1,3] |
Note:
1 <= A.length <= 1000
0 <= A[i] < 2^16
分析
先预处理一下每两个数的按位与的结果,然后再遍历每一个数。时间复杂度$O(n^2+max(A)n)$ 或 $O(n^2+n2^{16})$
代码1
1 | // 1024 ms |
代码2
1 | // 112 ms 线性表的执行时间比hashmap的执行时间少了不少 |
Author: Hatton.Liu
Link: http://hattonl.github.io/2020/03/31/leetcode-982/
License: 知识共享署名-非商业性使用 4.0 国际许可协议