We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 408dc13 commit 479e925Copy full SHA for 479e925
src/_Problems_/find-2-nums-adding-to-n/index.js
@@ -16,6 +16,20 @@ function findTwoNumsAddingToN(arr, number) {
16
return pair.length ? pair : false;
17
}
18
19
+function findIndicesOfTwoNumsAddingToN(nums, target) {
20
+ const store = new Set();
21
+ const pair = [];
22
+ for (let index in nums) {
23
+ if (store.has(target - nums[index])) {
24
+ pair.push(nums.indexOf(target - nums[index]));
25
+ pair.push(index);
26
+ break;
27
+ }
28
+ store.add(nums[index]);
29
30
+ return pair.length ? pair : false;
31
+}
32
+
33
// the Brute force approach
34
function findTwoNumsAddingToN2(arr, number) {
35
const pair = [];
0 commit comments