---
# System prepended metadata

title: 2341. Maximum Number of Pairs in Array
tags: [Leetcode, Easy]

---

# 2341. Maximum Number of Pairs in Array
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/maximum-number-of-pairs-in-array/description/
## Code
```java=
class Solution {
    public int[] numberOfPairs(int[] nums) {
        int pairs = 0;
        Set<Integer> set = new HashSet<>();
        for(int num:nums){
            if(set.contains(num)){
                set.remove(num);
                pairs++;
            }
            else set.add(num);
        }
        return new int[]{pairs, set.size()};
    }
}
```