1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| var twoSum = function(nums, target) { for(let i = 0, len = nums.length;i < len;i++){ for(let j = i + 1;j < len;j++) { if(nums[i] + nums[j] === target) { return [i, j]; } } } return -1; }; while(line=readline()){ var lines = line.split(" "); var a = lines[0]; var b = parseInt(lines[lines.length-1]); var arr=a.split(",").map(arr=>parseInt(arr)); var res=twoSum(arr,b); if(res===-1){ print(-1) }else{ print(res[0]+","+res[1]); }
}
|