題庫
上一題下一題
00:00

1. Two Sum

簡單雜湊表AmazonGoogleMicrosoft

Given an integer array nums and an integer target, return the indices of the two numbers that add up to target.

Each input has exactly one valid answer, and you may not use the same element twice.

範例 1:

輸入: nums = [2,7,11,15], target = 9
輸出: [0,1]

範例 2:

輸入: nums = [3,2,4], target = 6
輸出: [1,2]

限制條件:

  • 2 <= nums.length <= 10^4
  • Exactly one valid answer exists.
核心程式碼模式
● 已自動儲存第 1 行,第 1 欄