```
class Solution {
public:
int threeSumSmaller(vector<int>& nums, int target) {
sort(nums.begin(), nums.end());
int n = nums.size();
int result = 0;
int i,left,right;
for(i=0; i < n-2; i++)
{
left = i+1, right = n-1;
while(left<right)
(nums[i]+nums[left]+nums[right]<target) ? result += right - left, left++ : right--;
}
return result;
}
```

};