Skip to content

Commit c2cf5d0

Browse files
committed
update 1.two_sum.java
1 parent 6489cc1 commit c2cf5d0

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

1.two_sum.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
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+
*/
156
class Solution {
257
public int[] twoSum(int[] nums, int target) {
358
int[] result = new int[2];

0 commit comments

Comments
 (0)