-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ts solution to lc problem: No.0001 (#2012)
* feat: add solutions to lc problem: No.0001 * Update Solution.ts * style: format code and docs with prettier * Update README.md * Update README_EN.md --------- Co-authored-by: iam-abhishek-yadav <[email protected]>
- Loading branch information
1 parent
7902c7b
commit 623b53d
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function twoSum(nums: number[], target: number): number[] { | ||
const m: Map<number, number> = new Map(); | ||
|
||
for (let i = 0; ; ++i) { | ||
const x = nums[i]; | ||
const y = target - x; | ||
|
||
if (m.has(y)) { | ||
return [m.get(y)!, i]; | ||
} | ||
|
||
m.set(x, i); | ||
} | ||
} |