GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

Pythagorean Triplet

Suhas S Englisch 1 Karte

Karten in diesem Stapel (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--;
    }
    }

Informationen

Beschreibung
Karteikarten am Pythagorean Triplet, erstellt von Suhas S am 19/03/2018.
Erstellt von
Suhas S
Aufrufe
1
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck