2341. Maximum Number of Pairs in Array || In JAVA || Easy || Leetcode Problem #leetcode

preview_player
Показать описание
Hello Friends,
here I have discussed a leetcode problem. I solved this in JAVA.
I hope this video will help you.:)
Feel free to ask if you have any questions and you can give me any suggestions that I can improve!

Thanks for watching!

Leetcode Problems:
Рекомендации по теме
Комментарии
Автор

Code:-

class Solution {
public int[] numberOfPairs(int[] nums) {

HashSet<Integer> hs = new HashSet<>();
int[] ans = new int[2];

int count = 0;

for(int i : nums){
if(!hs.add(i)){
count++;
hs.remove(i);

}
}

ans[0]=count;
ans[1]=hs.size();

return ans;

}
}

quicklearninigwithsree