259. 3Sum Smaller
class Solution {
public int threeSumSmaller(int[] nums, int target) {
if (nums.length <= 2) {
return 0;
}
Arrays.sort(nums);
int count = 0;
for (int i = 0; i < nums.length; i++) {
int left = i + 1;
int right = nums.length - 1;
while (left < right) {
int sum = nums[i] + nums[left] + nums[right];
if (sum < target) {
count += right - left;
left++;
} else {
right--;
}
}
}
return count;
}
}
// TODO: Why count += right - left
?