File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,064 LeetCode solutions in JavaScript
1
+ # 1,065 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcode.com/ ] ( https://leetcode.com/ )
4
4
790
790
979|[ Distribute Coins in Binary Tree] ( ./solutions/0979-distribute-coins-in-binary-tree.js ) |Medium|
791
791
980|[ Unique Paths III] ( ./solutions/0980-unique-paths-iii.js ) |Hard|
792
792
981|[ Time Based Key-Value Store] ( ./solutions/0981-time-based-key-value-store.js ) |Medium|
793
+ 982|[ Triples with Bitwise AND Equal To Zero] ( ./solutions/0982-triples-with-bitwise-and-equal-to-zero.js ) |Hard|
793
794
985|[ Sum of Even Numbers After Queries] ( ./solutions/0985-sum-of-even-numbers-after-queries.js ) |Easy|
794
795
989|[ Add to Array-Form of Integer] ( ./solutions/0989-add-to-array-form-of-integer.js ) |Easy|
795
796
994|[ Rotting Oranges] ( ./solutions/0994-rotting-oranges.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 982. Triples with Bitwise AND Equal To Zero
3
+ * https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero/
4
+ * Difficulty: Hard
5
+ *
6
+ * Given an integer array nums, return the number of AND triples.
7
+ *
8
+ * An AND triple is a triple of indices (i, j, k) such that:
9
+ * - 0 <= i < nums.length
10
+ * - 0 <= j < nums.length
11
+ * - 0 <= k < nums.length
12
+ * - nums[i] & nums[j] & nums[k] == 0, where & represents the bitwise-AND operator.
13
+ */
14
+
15
+ /**
16
+ * @param {number[] } nums
17
+ * @return {number }
18
+ */
19
+ var countTriplets = function ( nums ) {
20
+ const map = new Map ( ) ;
21
+
22
+ for ( const first of nums ) {
23
+ for ( const second of nums ) {
24
+ const pairAnd = first & second ;
25
+ map . set ( pairAnd , ( map . get ( pairAnd ) || 0 ) + 1 ) ;
26
+ }
27
+ }
28
+
29
+ let result = 0 ;
30
+ for ( const third of nums ) {
31
+ for ( const [ pair , count ] of map ) {
32
+ if ( ( pair & third ) === 0 ) {
33
+ result += count ;
34
+ }
35
+ }
36
+ }
37
+
38
+ return result ;
39
+ } ;
You can’t perform that action at this time.
0 commit comments