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 not use the same element twice. The answer can be in any order.

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Only one valid answer exists.
Saving… · 2 lines
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
Console

Click Run to execute sample tests.