Leetcode#1. Two Sum
Problem
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.
Example 1:
1 | Input: nums = [2,7,11,15], target = 9 |
Example 2:
1 | Input: nums = [3,2,4], target = 6 |
Example 3:
1 | Input: nums = [3,3], target = 6 |
Constraints:
2 <= nums.length <= 10^4
10^9 <= nums[i] <= 10^9
10^9 <= target <= 10^9
- Only one valid answer exists.
Follow-up:
Can you come up with an algorithm that is less than
1 | O(n^2) |
time complexity?
Solve
1 | class Solution: |
本部落格所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。轉載請註明來自 Imisky!
評論