每次外层循环固定住一个数字, 然后剩下两个使用two pointer方法 每次初始化成头和尾 然后根据大小挪动一次
public class Solution {
public int threeSumSmaller(int[] nums, int target) {
if ( nums == null || nums.length < 3 )
return 0;
Arrays.sort ( nums );
int count = 0;
for ( int i = 0; i < nums.length - 2; i ++ ){
int p1 = i + 1;
int p2 = nums.length - 1;
while ( p1 < p2 ){
if ( nums [ p1 ] + nums [ p2 ] < target - nums[ i ] ){
count += p2 - p1;
p1 ++;
}
else{
p2 --;
}
}
}
return count;
}
}