Found two elements in the array is equal to the sum of all combinations of a specified number of

( 1 ) First to quickly sort the array 
( 2 ) to find the pointer around
 void findSumEqualTarget ( int [] ARR, int target, int len) {
     int First = 0 ;
     int Last len = 1 ;
     int SUM = 0 ;
     the while (First < Last) { 
        SUM = ARR [First] + ARR [Last];
         IF (SUM == target) { 
            the printf ( " % D, D% " , ARR [First], ARR [Last]); 
            First ++;
            last--;
        } else if (sum < target) {
            first++;
        } else {
            last--;
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/shijianchuzhenzhi/p/12513686.html
Recommended