Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5208f50

Browse files
committed
Add solution #1995
1 parent 172777e commit 5208f50

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,676 LeetCode solutions in JavaScript
1+
# 1,677 LeetCode solutions in JavaScript
22

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

@@ -1530,6 +1530,7 @@
15301530
1992|[Find All Groups of Farmland](./solutions/1992-find-all-groups-of-farmland.js)|Medium|
15311531
1993|[Operations on Tree](./solutions/1993-operations-on-tree.js)|Medium|
15321532
1994|[The Number of Good Subsets](./solutions/1994-the-number-of-good-subsets.js)|Hard|
1533+
1995|[Count Special Quadruplets](./solutions/1995-count-special-quadruplets.js)|Easy|
15331534
1996|[The Number of Weak Characters in the Game](./solutions/1996-the-number-of-weak-characters-in-the-game.js)|Medium|
15341535
2000|[Reverse Prefix of Word](./solutions/2000-reverse-prefix-of-word.js)|Easy|
15351536
2011|[Final Value of Variable After Performing Operations](./solutions/2011-final-value-of-variable-after-performing-operations.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* 1995. Count Special Quadruplets
3+
* https://leetcode.com/problems/count-special-quadruplets/
4+
* Difficulty: Easy
5+
*
6+
* Given a 0-indexed integer array nums, return the number of distinct quadruplets
7+
* (a, b, c, d) such that:
8+
* - nums[a] + nums[b] + nums[c] == nums[d], and
9+
* - a < b < c < d
10+
*/
11+
12+
/**
13+
* @param {number[]} nums
14+
* @return {number}
15+
*/
16+
var countQuadruplets = function(nums) {
17+
const map = new Map();
18+
let result = 0;
19+
20+
for (let c = nums.length - 2; c >= 2; c--) {
21+
map.set(nums[c + 1], (map.get(nums[c + 1]) || 0) + 1);
22+
for (let a = 0; a < c - 1; a++) {
23+
for (let b = a + 1; b < c; b++) {
24+
const sum = nums[a] + nums[b] + nums[c];
25+
result += map.get(sum) || 0;
26+
}
27+
}
28+
}
29+
30+
return result;
31+
};

0 commit comments

Comments
 (0)