java.lang.Object
g0901_1000.s0982_triples_with_bitwise_and_equal_to_zero.Solution

public class Solution extends Object
982 - Triples with Bitwise AND Equal To Zero.<p>Hard</p> <p>Given an integer array nums, return <em>the number of <strong>AND triples</strong></em>.</p> <p>An <strong>AND triple</strong> is a triple of indices <code>(i, j, k)</code> such that:</p> <ul> <li><code>0 <= i < nums.length</code></li> <li><code>0 <= j < nums.length</code></li> <li><code>0 <= k < nums.length</code></li> <li><code>nums[i] & nums[j] & nums[k] == 0</code>, where <code>&</code> represents the bitwise-AND operator.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [2,1,3]</p> <p><strong>Output:</strong> 12</p> <p><strong>Explanation:</strong> We could choose the following i, j, k triples:</p> <p>(i=0, j=0, k=1) : 2 & 2 & 1</p> <p>(i=0, j=1, k=0) : 2 & 1 & 2</p> <p>(i=0, j=1, k=1) : 2 & 1 & 1</p> <p>(i=0, j=1, k=2) : 2 & 1 & 3</p> <p>(i=0, j=2, k=1) : 2 & 3 & 1</p> <p>(i=1, j=0, k=0) : 1 & 2 & 2</p> <p>(i=1, j=0, k=1) : 1 & 2 & 1</p> <p>(i=1, j=0, k=2) : 1 & 2 & 3</p> <p>(i=1, j=1, k=0) : 1 & 1 & 2</p> <p>(i=1, j=2, k=0) : 1 & 3 & 2</p> <p>(i=2, j=0, k=1) : 3 & 2 & 1</p> <p>(i=2, j=1, k=0) : 3 & 1 & 2</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [0,0,0]</p> <p><strong>Output:</strong> 27</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 1000</code></li> <li><code>0 <= nums[i] < 2<sup>16</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countTriplets

      public int countTriplets(int[] nums)