-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray.java
31 lines (28 loc) · 811 Bytes
/
Array.java
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
public class Array{
public static void main(String args[]) {
int[] val = {3,2,4};
int target = 6;
int[] answer = twoSum(val, target);
for (int i = 0; i < answer.length; i++){
System.out.println(answer[i]);
}
}
public static int[] twoSum(int[] nums, int target) {
int possibleValue;
int[] ans = new int[2];
for(int i = 0; i < nums.length; i++)
{
possibleValue = nums[i];
for(int j = 0 ; j < nums.length; j++)
{
if(possibleValue + nums[j] == target && i != j)
{
ans[0] = i;
ans[1] = j;
break;
}
}
}
return ans;
}
}