Daily-Interview-Question icon indicating copy to clipboard operation
Daily-Interview-Question copied to clipboard

没考虑时间复杂度

Open xml123 opened this issue 7 years ago • 0 comments

function test(num,target){
    const arr=[]
    for(let i=0;i<num.length-1;i++){
        if(num[i]<= target){
	    for(let j=i+1;j<num.length;j++){
	        if(num[j]<=target && num[i]+num[j] === target){
		    arr.push(i)
		    arr.push(j)
		    console.log(arr);
		    return arr;
		}
	    }
	}
    }
    console.log(arr);
    return arr;
}

xml123 avatar Nov 13 '19 07:11 xml123