-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreeSum.java
More file actions
24 lines (22 loc) · 747 Bytes
/
threeSum.java
File metadata and controls
24 lines (22 loc) · 747 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
import java.util.Arrays;
public class threeSum{
public int[] twoSum(int[] nums, int target) {
for (int i = 0; i < nums.length; i++)
{
for (int j = i + 1; j < nums.length; j++)
{ // Start from i+1
for(int k= j+1;k<nums.length;k++){
if (nums[i] + nums[j]+nums[k] == target) {
return new int[]{i,j,k}; // Corrected return statement
}
}
}
}
return new int[]{}; // If no solution is found
}
public static void main(String args[]){
int a[]={1,2,3,4,5};
threeSum b= new threeSum();
System.out.println(Arrays.toString(b.twoSum(a,6)));
}
}