Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat files #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Reformat files #195

wants to merge 2 commits into from

Conversation

shivam83184
Copy link

import java.util.*;

class Triplet
{

// function to print triplets with 0 sum
static void findTriplets(int arr[], int n)
{
    boolean found = false;

    for (int i = 0; i < n - 1; i++)
    {
        // Find all pairs with sum equals to
        // "-arr[i]"
        HashSet<Integer> s = new HashSet<Integer>();
        for (int j = i + 1; j < n; j++)
        {
            int x = -(arr[i] + arr[j]);
            if (s.contains(x))
            {
                System.out.printf("%d %d %d\n", x, arr[i], arr[j]);
                found = true;
            }
            else
            {
                s.add(arr[j]);
            }
        }
    }

    if (found == false)
    {
        System.out.printf(" No Triplet Found\n");
    }
}

// Driver code
public static void main(String[] args)
{
    int arr[] = {0, -1, 2, -3, 1};
    int n = arr.length;
    findTriplets(arr, n);
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant