Skip to content

Commit effbbb5

Browse files
committed
Add solution #982
1 parent ec3ec9b commit effbbb5

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,064 LeetCode solutions in JavaScript
1+
# 1,065 LeetCode solutions in JavaScript
22

33
[https://leetcode.com/](https://leetcode.com/)
44

@@ -790,6 +790,7 @@
790790
979|[Distribute Coins in Binary Tree](./solutions/0979-distribute-coins-in-binary-tree.js)|Medium|
791791
980|[Unique Paths III](./solutions/0980-unique-paths-iii.js)|Hard|
792792
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|
793794
985|[Sum of Even Numbers After Queries](./solutions/0985-sum-of-even-numbers-after-queries.js)|Easy|
794795
989|[Add to Array-Form of Integer](./solutions/0989-add-to-array-form-of-integer.js)|Easy|
795796
994|[Rotting Oranges](./solutions/0994-rotting-oranges.js)|Medium|
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
};

0 commit comments

Comments
 (0)