[leetcode] Two Sum

ironcat·2022년 3월 7일
0

알고리즘

목록 보기
1/17
  1. Two Sum
    Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

You can return the answer in any order.

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for i, v1 in enumerate(nums):
            index = i + 1
            tmp = nums[index:]
            for j, v2 in enumerate(tmp):
                if v1 + v2 == target:
                    return [i, index+j]
profile
공부하는 블로그

0개의 댓글