¡GoConqr estrena diseño! Cuéntanos qué te parece.

Fichas

Pythagorean Triplet

Suhas S Inglés 1 ficha

Fichas del conjunto (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--;
    }
    }

Información

Descripción
Fichas sobre Pythagorean Triplet, creado por Suhas S el 19/03/2018.
Creado por
Suhas S
Visitas
1
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?