We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 4cf7b2c + 00b6cde commit d754bb7Copy full SHA for d754bb7
1 file changed
two-sum/nakjun12.ts
@@ -0,0 +1,20 @@
1
+/*
2
+ * TC: O(n)
3
+ * SC: O(n)
4
+ * */
5
+function twoSum(nums: number[], target: number): number[] {
6
+ const indices = {};
7
+
8
+ for (let i = 0; i < nums.length; i++) {
9
+ const curNum = nums[i];
10
+ const complement = target - curNum;
11
12
+ if (complement in indices) {
13
+ return [indices[complement], i];
14
+ }
15
16
+ indices[curNum] = i;
17
18
19
+ return [];
20
+}
0 commit comments