public int threeSumSmaller(int[] nums, int target) {
        if (nums == null || nums.length < 3) return 0;

        Arrays.sort(nums);
        int cnt = 0;
        for (int i = 0; i < nums.length - 2; ++i) {
            int low = i + 1, high = nums.length - 1;
            while (low < high) {
                if (nums[i] + nums[low] + nums[high] < target) {
                    cnt += high - low; // key: O(1) time to count satisfied results
                    ++low;
                } else {
                    --high;
                }
            }
        }
        return cnt;
    }