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.
1 parent daa942f commit e39c2e5Copy full SHA for e39c2e5
two-sum/gitsunmin.ts
@@ -0,0 +1,16 @@
1
+/**
2
+ * https://leetcode.com/problems/two-sum
3
+ * time complexity : O(n)
4
+ * space complexity : O(n)
5
+ */
6
+function twoSum(nums: number[], target: number): number[] {
7
+ const m = new Map<number, number>();
8
+
9
+ for (let i = 0; i < nums.length; i++) {
10
+ if (m.has(nums[i]))
11
+ return [m.get(nums[i]), i];
12
+ m.set(target - nums[i], i);
13
+ }
14
15
+ return [-1, -1];
16
+};
0 commit comments