|
| 1 | +/* |
| 2 | + * @lc app=leetcode id=1 lang=java |
| 3 | + * |
| 4 | + * [1] Two Sum |
| 5 | + * |
| 6 | + * https://leetcode.com/problems/two-sum/description/ |
| 7 | + * |
| 8 | + * algorithms |
| 9 | + * Easy (46.11%) |
| 10 | + * Total Accepted: 3.7M |
| 11 | + * Total Submissions: 8M |
| 12 | + * Testcase Example: '[2,7,11,15]\n9' |
| 13 | + * |
| 14 | + * Given an array of integers nums and an integer target, return indices of the |
| 15 | + * two numbers such that they add up to target. |
| 16 | + * |
| 17 | + * You may assume that each input would have exactly one solution, and you may |
| 18 | + * not use the same element twice. |
| 19 | + * |
| 20 | + * You can return the answer in any order. |
| 21 | + * |
| 22 | + * |
| 23 | + * Example 1: |
| 24 | + * |
| 25 | + * |
| 26 | + * Input: nums = [2,7,11,15], target = 9 |
| 27 | + * Output: [0,1] |
| 28 | + * Output: Because nums[0] + nums[1] == 9, we return [0, 1]. |
| 29 | + * |
| 30 | + * |
| 31 | + * Example 2: |
| 32 | + * |
| 33 | + * |
| 34 | + * Input: nums = [3,2,4], target = 6 |
| 35 | + * Output: [1,2] |
| 36 | + * |
| 37 | + * |
| 38 | + * Example 3: |
| 39 | + * |
| 40 | + * |
| 41 | + * Input: nums = [3,3], target = 6 |
| 42 | + * Output: [0,1] |
| 43 | + * |
| 44 | + * |
| 45 | + * |
| 46 | + * Constraints: |
| 47 | + * |
| 48 | + * |
| 49 | + * 2 <= nums.length <= 10^3 |
| 50 | + * -10^9 <= nums[i] <= 10^9 |
| 51 | + * -10^9 <= target <= 10^9 |
| 52 | + * Only one valid answer exists. |
| 53 | + * |
| 54 | + * |
| 55 | + */ |
1 | 56 | class Solution {
|
2 | 57 | public int[] twoSum(int[] nums, int target) {
|
3 | 58 | int[] result = new int[2];
|
|
0 commit comments