---
# System prepended metadata

title: 2465. Number of Distinct Averages
tags: [Leetcode, Two Pointers, Easy]

---

# 2465. Number of Distinct Averages
###### tags: `Leetcode` `Easy` `Two Pointers`
Link: https://leetcode.com/problems/number-of-distinct-averages/description/
## 思路
先排序 然后用双指针记录所有min和max的pair的和即可
## Code
```java=
class Solution {
    public int distinctAverages(int[] nums) {
        Set<Integer> set = new HashSet<>();
        int n = nums.length;
        Arrays.sort(nums);
        int l=0, r=n-1;
        for(l=0; l<n/2; l++){
            set.add(nums[l]+nums[r]);
            r--;
        }
        return set.size();
    }
}
```