ZLYNX

Lần đầu tiên python

Python with two-sum leetcode

Testcase:

image

Result:

class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: _dict = {} for i in range(len(nums)): x = target - nums[i] if x not in _dict: _dict[nums[i]] = i else: return [i, _dict[x]]