const twoSum = (nums, target) => {
// 아래 코드를 작성해주세요.
let count = 0;
let arr= [];
for(let i = 0; i < nums.length; i++) {
if(nums[i] + nums[count] !== target){
count + 1;
}else if(nums[i] + nums[count] === target){
return arr.push(i, j);
}
}
}
let number = [4, 9, 11, 14, 44, 22];
console.log(twoSum(number, 66))
undefined
const twoSum = (nums, target) => {
// 아래 코드를 작성해주세요.
let arr = [];
for(let i = 0; i < nums.length; i++) {
for(let j = 1; j < nums.length; j++) {
if(nums[i] + nums[j] === target){
arr.push(i, j)
}
}
}return arr
};
let number = [4, 9, 11, 14, 44, 22];
console.log(twoSum(number, 15))
const twoSum = (nums, target) => {
// 아래 코드를 작성해주세요.
for(let i = 0; i < nums.length; i++) {
for(let j = i + 1; j < nums.length; j++) {
if(nums[i] + nums[j] === target){
return [i, j];
}
}
}
};
let number = [4, 9, 11, 14, 44, 22];
console.log(twoSum(number, 66))
생각도 못했던 것을 동기분이 알려주셨다!