Skip to content

Commit

Permalink
feat: add ts solution to lc problem: No.0001 (#2012)
Browse files Browse the repository at this point in the history
* 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
iam-abhishek-yadav and iam-abhishek-yadav authored Nov 24, 2023
1 parent 7902c7b commit 623b53d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
19 changes: 19 additions & 0 deletions solution/0000-0099/0001.Two Sum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,25 @@ class Solution {
}
```

### **TypeScript**

```ts
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);
}
}
```

### **...**

```
Expand Down
19 changes: 19 additions & 0 deletions solution/0000-0099/0001.Two Sum/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ class Solution {
}
```

### **TypeScript**

```ts
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);
}
}
```

### **...**

```
Expand Down
14 changes: 14 additions & 0 deletions solution/0000-0099/0001.Two Sum/Solution.ts
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);
}
}

0 comments on commit 623b53d

Please sign in to comment.