Hash all the elements of A.

if B[i] is not in hash add into the result. 0<=i<sizeof(B)

if B[i] is not in hash add into the result. 0<=i<sizeof(B)

Hash all the elements of A.

if B[i] is not in hash add into the result. 0<=i<sizeof(B)

if B[i] is not in hash add into the result. 0<=i<sizeof(B)

It was given that pair will be unique.

void FindPair(int* arr, int size, int sum)

{

for(int i=0; i<size; ++i)

hash[arr[i]] = 1;

for(int i=0; i<size; ++i)

{

if(hash[sum-arr[i]])

cout<<"Pair found ( " <<arr[i]<<", "<<sum-arr[i]<<" )";

}

}

void FindPair(int* arr, int size, int sum)

{

for(int i=0; i<size; ++i)

hash[arr[i]] = 1;

for(int i=0; i<size; ++i)

{

if(hash[sum-arr[i]])

cout<<"Pair found ( " <<arr[i]<<", "<<sum-arr[i]<<" )";

}

}

Subscribe to:
Posts (Atom)