Leetcode - 1. Two Sum
Coding Test

Leetcode - 1. Two Sum

일시불

문제

Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

답안

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for idx, num in enumerate(nums):
            diff = target - num
            if diff in nums[idx+1:]:
                return [idx, idx+1+nums[idx+1:].index(diff)]