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

Commit2f26845

Browse files
committed
1 parentb5a1430 commit2f26845

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎src/two-sum.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
* two0sum.js
7+
*
8+
*@param {number[]} nums
9+
*@param {number} target
10+
*@return {number[]}
11+
*/
12+
lettwoSum=function(nums,target){
13+
for(leti=nums.length-1;i>=0;i--){
14+
for(letj=0;j<i;j++){
15+
if(addition(nums[i],nums[j])===target){
16+
return[j,i];
17+
}
18+
}
19+
}
20+
};
21+
22+
// add a with b and return it
23+
letaddition=function(a,b){
24+
returna+b;
25+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp