Skip to content

Commit 97a482f

Browse files
Update DivideArrayintoEqualPairs.java
1 parent 796213a commit 97a482f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

DivideArrayintoEqualPairs.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.Arrays;
2+
3+
public class DivideArrayintoEqualPairs {
4+
5+
public boolean divideArray(final int[] nums) {
6+
7+
final int[] count = new int[501];
8+
9+
for (final int num : nums)
10+
++count[num];
11+
12+
return Arrays.stream(count).allMatch(c -> c % 2 == 0);
13+
14+
}
15+
public static void main(String[] args) {
16+
Solution d=new Solution();
17+
int[] nums = {3, 2, 3, 2, 2, 2};
18+
boolean result = d.divideArray(nums);
19+
System.out.println("Can divide array into equal pairs? " + result);
20+
}
21+
}

0 commit comments

Comments
 (0)