You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the main has the following code System.out.println(solution(new int[] { 7, 9, 3, 9, 3, 9, 9 })); an incorrect number is returned by solution2.
The below code for solution2 works well and is of same order:
publicstaticintsolution2(int[] A) {
// write your code in Java SE 8HashSet<Integer> dups = newHashSet<Integer>();
ArrayList<Integer> tmp = newArrayList<>();
for (inti = 0; i < A.length; i++) {
if (dups.add(A[i])) {
tmp.add(A[i]);
}
else{
tmp.remove(newInteger(A[i]));
}
}
returntmp.get(0);
}
The text was updated successfully, but these errors were encountered:
If the main has the following code
System.out.println(solution(new int[] { 7, 9, 3, 9, 3, 9, 9 }));
an incorrect number is returned by solution2.The below code for solution2 works well and is of same order:
The text was updated successfully, but these errors were encountered: