나의 답:
class Solution(object):
def twoSum(self, nums, target):
for x in range(0, len(nums)):
for y in range(x+1, len(nums)):
if (nums[x] + nums[y] == target):
return [x, y]
참고할 답:
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
seen = {}
for idx,num in enumerate(nums):
remainder = target - num
if remainder in seen:
return [seen[remainder], idx]
else:
seen[num] = idx
enumerate 함수가 있는 줄도 몰랐다.. 파이썬 공부를 다시해야겠다.