File tree 2 files changed +14
-0
lines changed
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -10,3 +10,4 @@ https://neetcode.io/roadmap
10
10
| --- | ----------------------------------------------------------------------- | ---------- | ---------------------------------------------------- |
11
11
| 217 | [ Contains Duplicate] ( https://leetcode.com/problems/contains-duplicate/ ) | Easy | [ TypeScript] ( ./TypeScript/217.contains-duplicate.ts ) |
12
12
| 242 | [ Valid Anagram] ( https://leetcode.com/problems/valid-anagram/ ) | Easy | [ TypeScript] ( ./TypeScript/242.valid-anagram.ts ) |
13
+ | 242 | [ Two Sum] ( https://leetcode.com/problems/two-sum/ ) | Easy | [ TypeScript] ( ./TypeScript/1.two-sum.ts ) |
Original file line number Diff line number Diff line change
1
+ function twoSum ( nums : number [ ] , target : number ) : number [ ] {
2
+ const map = new Map < number , number > ( ) ;
3
+
4
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
5
+ const diff = target - nums [ i ] ;
6
+
7
+ if ( map . has ( diff ) ) return [ map . get ( diff ) ! , i ] ;
8
+
9
+ map . set ( nums [ i ] , i ) ;
10
+ }
11
+
12
+ return [ - 1 , - 1 ] ;
13
+ }
You can’t perform that action at this time.
0 commit comments