GoConqr has a new look! Let us know what you think.

Flashcards

Pythagorean Triplet

Suhas S English 1 card

Cards in this deck (1)

  1. 1Given an integer array find all Pythagorean triplets.static boolean isTriplet(int arr[], int n)
    {
    // Square array elements
    for (int i=0; i= 2; i--)
    {
    // To find the other two elements, start two index
    // variables from two corners of the array and move
    // them toward each other
    int l = 0; // index of the first element in arr[0..i-1]
    int r = i-1; // index of the last element in arr[0..i-1]
    while (l < r)
    {
    // A triplet found
    if (arr[l] + arr[r] == arr[i])
    return true;
    // Else either move 'l' or 'r'
    if (arr[l] + arr[r] < arr[i])
    l++;
    else
    r--;
    }
    }

Information

Description
Flashcards on Pythagorean Triplet, created by Suhas S on 19/03/2018.
Created by
Suhas S
Views
1
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?