Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Typescript #1 two sum#1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hijiangtao merged 3 commits intohijiangtao:masterfromagb:typescript-#1-two-sum
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr

| ID | Title | Solution | Difficulty |
|-----|-------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|------------|
| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [JavaScript](./src/two-sum/res.js) | Easy |
| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [JavaScript](./src/two-sum/res.js)· [TypeScript](./src/two-sum/res.ts) | Easy |
| 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [JavaScript](./src/add-two-numbers/res.js) | Medium |
| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [JavaScript](./src/longest-substring-without-repeating-characters/res.js) | Medium |
| 4 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [JavaScript](./src/median-of-two-sorted-arrays/res.js) | Hard |
Expand Down
28 changes: 28 additions & 0 deletionssrc/two-sum/res.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
/**
* Problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target.
*
* You may assume that each input would have exactly one solution, and you may not use the same element twice.
*
*
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/

const twoSum =(nums:Array<number>, target:number): Array<number> => {

for (let i = nums.length - 1; i >= 0; i--) {
for (let j = 0; j < i; j++) {
if ( addition(nums[i], nums[j]) === target ) {
return [j, i];
}
}
}

return [];
};

// add a with b and return it
const addition = (a:number, b:number) => {
return a + b;
};

[8]ページ先頭

©2009-2025 Movatter.jp