two sum problem in c 2b 2b

Solutions on MaxInterview for two sum problem in c 2b 2b by the best coders in the world

showing results for - "two sum problem in c 2b 2b"
Davide
04 Oct 2016
1bool twosum(int A[], int N, int X) {
2  	sort(A, A+N);
3    int i = 0, j = N-1;
4    while (i < j) {
5        if (A[i] + A[j] == X) return true;
6        else if (A[i] + A[j] > X) j--;
7        else i++;
8    }
9    return false;
10}