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

Commitfb20f58

Browse files
committed
added first solution with test case
1 parent35478af commitfb20f58

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

‎src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
importrun1from'./solutions/1';
2+
3+
run1();
4+
15

‎src/solutions/1/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
importtwoSumfrom'./twoSum';
2+
3+
construn=()=>{
4+
constinput :number[]=[2,7,11,15];
5+
consttarget :number=9;
6+
constexpectedOutput :number[]=[0,1];
7+
8+
9+
console.info("Input : ",input)
10+
console.info("Target: ",target)
11+
console.info("Expected Output: ",expectedOutput)
12+
console.log("=============================")
13+
console.time("execution")
14+
console.log("Output:::::",twoSum(input,target))
15+
console.timeEnd("execution")
16+
}
17+
18+
exportdefaultrun;

‎src/solutions/1/twoSum.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
importtwoSumfrom"./twoSum";
2+
3+
test('solution 1 - twoSum',()=>{
4+
expect(twoSum([2,7,11,15],9)).toEqual([0,1]);
5+
expect(twoSum([3,2,4],6)).toEqual([1,2]);
6+
expect(twoSum([3,3],6)).toEqual([0,1]);
7+
});

‎src/solutions/1/twoSum.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
consttwoSum=(nums:number[],target:number):number[]|undefined=>{
2+
letoutput:number[]=[];
3+
for(leti=0;i<nums.length;i++){
4+
for(letj=i+1;j<nums.length;j++){
5+
if(nums[i]+nums[j]===target){
6+
output.push(i,j);
7+
returnoutput;
8+
}
9+
}
10+
}
11+
}
12+
13+
exportdefaulttwoSum;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp