We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cd76a47 commit d94e21bCopy full SHA for d94e21b
scripts/algorithms/M/Maximum Number of Pairs in Array/Maximum Number of Pairs in Array.java
@@ -1,21 +1,22 @@
1
+// Runtime: 4 ms (Top 21.09%) | Memory: 42.4 MB (Top 76.38%)
2
class Solution {
3
public int[] numberOfPairs(int[] nums) {
-
4
+
5
if(nums.length == 1)
6
return new int[]{0,1};
7
8
HashSet<Integer> set = new HashSet<>();
9
10
int pairs=0;
11
for(int i : nums){
12
if(!set.contains(i)){
- set.add(i); // No pair present
13
+ set.add(i); // No pair present
14
}else{
- set.remove(i); // Pair found
15
- pairs++;
+ set.remove(i); // Pair found
16
+ pairs++;
17
}
18
19
- return new int[]{pairs,set.size()};
20
+ return new int[]{pairs,set.size()};
21
-}
22
+}
0 commit comments