-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1TwoSum.java
More file actions
35 lines (27 loc) · 832 Bytes
/
1TwoSum.java
File metadata and controls
35 lines (27 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*Description:
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.
*/
class TwoSum
{
public int[] twoSum(int[] nums, int target)
{
//int x = 0;
int[] outputArr = new int[2];
for(int x = 0; x < nums.length; x++)
{
for(int i = 1; i < nums.length; i++)
{
if((nums[x] + nums[i]) == target)
{
outputArr[0] = x;
outputArr[1] = i;
return outputArr;
}
}
x++;
}
return outputArr;
}
}