public static int TwoSumFast(int[] array) { int count = 0; QuickSort.Sort(array, 0, array.Length - 1); for (int i = 0; i < array.Length; i++) { if (BinarySort_1.BinarySort(array, -array[i], i + 1, array.Length) > i) { count++; } } return(count); }
public static int ThreeSum(int[] array) { int count = 0; QuickSort.Sort(array, 0, array.Length - 1); for (int i = 0; i < array.Length; i++) { for (int j = i + 1; j < array.Length; j++) { int position = BinarySort_1.BinarySort(array, -array[i] - array[j], i, array.Length); if (position > i) { count++; } } } return(count); }