Skip to content

Commit 3dc1c18

Browse files
problme 68 solved
1 parent 430239e commit 3dc1c18

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

File renamed without changes.

problem68/problem68.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,22 @@
55
66
*/
77

8-
8+
const twoIndices = (arr, target) => {
9+
const allNumbers = {};
10+
11+
for (let i = 0; i < arr.length; i++) {
12+
const firstNum = arr[i];
13+
const secondNum = target - firstNum;
14+
if (allNumbers.hasOwnProperty(secondNum)) {
15+
const firstIndex = allNumbers[secondNum];
16+
return [firstIndex, i];
17+
}
18+
19+
allNumbers[firstNum] = i;
20+
}
21+
22+
return [];
23+
}
24+
25+
// Example usage:
26+
console.log(twoIndices([1, 3, 6, 8, 11, 15], 9));

0 commit comments

Comments
 (0)