982. Triples with Bitwise AND Equal To Zero Hard

@problem@discussion
#Array#Hash Table#Bit Manipulation



1/**
2 * [982] Triples with Bitwise AND Equal To Zero
3 *
4 * Given an integer array nums, return the number of AND triples.
5 * An AND triple is a triple of indices (i, j, k) such that:
6 * 
7 * 	0 <= i < nums.length
8 * 	0 <= j < nums.length
9 * 	0 <= k < nums.length
10 * 	nums[i] &amp; nums[j] &amp; nums[k] == 0, where &amp; represents the bitwise-AND operator.
11 * 
12 *  
13 * Example 1:
14 * 
15 * Input: nums = [2,1,3]
16 * Output: 12
17 * Explanation: We could choose the following i, j, k triples:
18 * (i=0, j=0, k=1) : 2 &amp; 2 &amp; 1
19 * (i=0, j=1, k=0) : 2 &amp; 1 &amp; 2
20 * (i=0, j=1, k=1) : 2 &amp; 1 &amp; 1
21 * (i=0, j=1, k=2) : 2 &amp; 1 &amp; 3
22 * (i=0, j=2, k=1) : 2 &amp; 3 &amp; 1
23 * (i=1, j=0, k=0) : 1 &amp; 2 &amp; 2
24 * (i=1, j=0, k=1) : 1 &amp; 2 &amp; 1
25 * (i=1, j=0, k=2) : 1 &amp; 2 &amp; 3
26 * (i=1, j=1, k=0) : 1 &amp; 1 &amp; 2
27 * (i=1, j=2, k=0) : 1 &amp; 3 &amp; 2
28 * (i=2, j=0, k=1) : 3 &amp; 2 &amp; 1
29 * (i=2, j=1, k=0) : 3 &amp; 1 &amp; 2
30 * 
31 * Example 2:
32 * 
33 * Input: nums = [0,0,0]
34 * Output: 27
35 * 
36 *  
37 * Constraints:
38 * 
39 * 	1 <= nums.length <= 1000
40 * 	0 <= nums[i] < 2^16
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero/
46// discuss: https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn count_triplets(nums: Vec<i32>) -> i32 {
52        0
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_982() {
64    }
65}
66


Back
© 2025 bowen.ge All Rights Reserved.