> For the complete documentation index, see [llms.txt](https://junnie.gitbook.io/nine-chapter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://junnie.gitbook.io/nine-chapter/7.two-pointers/443two-sum-greater-than-target.md).

# 443.Two Sum - Greater than target

## 1.Description(Medium)

Given an array of integers, find how many pairs in the array such that their sum is bigger than a specific target number. Please return the number of pairs.

**Example**

Given numbers =`[2, 7, 11, 15]`, target =`24`. Return`1`. (11 + 15 is the only pair)

[**Challenge**](https://www.lintcode.com/en/problem/two-sum-greater-than-target/#challenge)

Do it in O(1) extra space and O(nlogn) time.

## 2.Code

跟609相似

```
 public int twoSum2(int[] nums, int target) {
        if(nums==null || nums.length<2){
            return 0;
        }
        Arrays.sort(nums);
        int head=0;
        int tail=nums.length-1;
        int result=0;
        while(head<tail){
            int sum=nums[head]+nums[tail];
            if(sum>target){
                result=result+(tail-head);
                tail--;
            }else{
                head++;
            }
        }
        return result;
    }
```
