SOURCE

function twoSum(nums: number[], target: number): number[] {  
    let temp = [];
    for(let i in nums){
        // console.log(num)
        const cha = target - nums[i];
        const end = nums.lastIndexOf(cha)
        
        if(end!=-1&&Number(i)!=end){
            return [Number(i),end]
        }
        
    }
};

console.log(twoSum([2,7,11,15],9));
console.log(twoSum([3,2,4],6));
console.log(twoSum([3,3],6));
console 命令行工具 X clear

                    
>
console