```
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)
{
if(nums[i]+nums[left]+nums[right]<target)
{
result = result+(right-left);
left++;
}
else
{
right--;
}
}
}
return result;
}
};
```