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

Commitaec6f6c

Browse files
authored
feat: Typescripthijiangtao#1 two sum (hijiangtao#1)
1 parent9499040 commitaec6f6c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
88

99
| ID| Title| Solution| Difficulty|
1010
|-----|-------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|------------|
11-
| 1|[Two Sum](https://leetcode.com/problems/two-sum/)|[JavaScript](./src/two-sum/res.js)| Easy|
11+
| 1|[Two Sum](https://leetcode.com/problems/two-sum/)|[JavaScript](./src/two-sum/res.js)·[TypeScript](./src/two-sum/res.ts)| Easy|
1212
| 2|[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/)|[JavaScript](./src/add-two-numbers/res.js)| Medium|
1313
| 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|
1414
| 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|

‎src/two-sum/res.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target.
3+
*
4+
* You may assume that each input would have exactly one solution, and you may not use the same element twice.
5+
*
6+
*
7+
*@param {number[]} nums
8+
*@param {number} target
9+
*@return {number[]}
10+
*/
11+
12+
consttwoSum=(nums:Array<number>,target:number):Array<number>=>{
13+
14+
for(leti=nums.length-1;i>=0;i--){
15+
for(letj=0;j<i;j++){
16+
if(addition(nums[i],nums[j])===target){
17+
return[j,i];
18+
}
19+
}
20+
}
21+
22+
return[];
23+
};
24+
25+
// add a with b and return it
26+
constaddition=(a:number,b:number)=>{
27+
returna+b;
28+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp