class Solution(object):
    def threeSumSmaller(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        res = 0
        nums.sort()
        for i, num in enumerate(nums):
            # Ҫڱi±ϳtarget - num 
            t = target - num
            left, right = i + 1, len(nums) - 1
            while left < right:
                if nums[left] + nums[right] >= t:
                    right -= 1 #̫ˣ԰ѺС
                elif nums[left] + nums[right] < t:
                    res += right - left #£left롾left + 1 rightһһ
                    left += 1

        return res