Skip to content

Commit fc5421b

Browse files
authored
Update js codes.docx
1 parent 675b03d commit fc5421b

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

js codes.docx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,8 +3384,28 @@ function moveZeroes(arr){
33843384
}
33853385
console.log(moveZeroes([0,2,3,0,50,0,3,0,8,2,0]))
33863386
=======================================================================================================================================================================
3387-
3388-
3387+
function sumofTwopair(arr, target){
3388+
for(let i=0; i<arr.length; i++){
3389+
for(let j=i+1; j<arr.length; j++){
3390+
if(arr[i]+arr[j] === target) return true
3391+
}
3392+
}
3393+
return false
3394+
}
3395+
console.log(sumofTwopair([0,22,3,0,50,0,3,0,8,2,0],5))
3396+
--------------------------------------------------------
3397+
function sumofTwopair(arr, target){
3398+
let s = new Set();
3399+
for(let item of arr){
3400+
if(s.has(target-item)){
3401+
return true
3402+
}else{
3403+
s.add(item)
3404+
}
3405+
}
3406+
return false
3407+
}
3408+
console.log(sumofTwopair([0,2,3,0,50,0,3,0,8,2,0],5))
33893409
=======================================================================================================================================================================
33903410

33913411
=======================================================================================================================================================================

0 commit comments

Comments
 (0)