(int A[], int n, int X)
| 3 | //Function to find if there exists a triplet in the |
| 4 | //array A[] which sums up to X. |
| 5 | public static boolean find3Numbers(int A[], int n, int X) { |
| 6 | |
| 7 | // Your code |
| 8 | for(int i=0;i<n-2;i++) |
| 9 | { |
| 10 | HashSet<Integer> set = new HashSet<>(); |
| 11 | int toFind=X-A[i]; |
| 12 | for(int j=i+1;j<n;j++) |
| 13 | { |
| 14 | if(set.contains(toFind-A[j])) |
| 15 | { |
| 16 | return true; |
| 17 | } |
| 18 | set.add(A[j]); |
| 19 | } |
| 20 | } |
| 21 | return false; |
| 22 | } |
| 23 | } |