```
class Solution {
public:
int threeSumSmaller(vector<int>& nums, int target) {
sort(nums.begin(), nums.end());
int count = 0;
for (int i = 0; i < nums.size(); ++ i)
for (int j = i + 1, k = (int)nums.size() - 1; j < k;)
if (nums[j] + nums[k] < target - nums[i])
count += k - j++;
else
k --;
return count;
}
};
```