|
@@ -37,24 +37,36 @@ public class ArrayUtility<SomeType> {
|
37
|
37
|
|
38
|
38
|
public SomeType findEvenOccurringValue() {
|
39
|
39
|
|
40
|
|
- if(array.length==1){
|
41
|
|
- return array[0];
|
42
|
|
- }
|
43
|
|
- Arrays.sort(array);
|
44
|
|
- for(int i=0;i<array.length-1;){
|
45
|
|
- if(array[i]!=array[i+1]){
|
46
|
|
- i+=2;
|
47
|
|
- }else{
|
|
40
|
+// if(array.length==1){
|
|
41
|
+// return array[0];
|
|
42
|
+// }
|
|
43
|
+// Arrays.sort(array);
|
|
44
|
+// for(int i=0;i<array.length-1;){
|
|
45
|
+// if(array[i]!==array[i+1]){
|
|
46
|
+// i+=2;
|
|
47
|
+// }else{
|
|
48
|
+// return array[i];
|
|
49
|
+// }
|
|
50
|
+// }
|
|
51
|
+// return array[array.length-1];
|
|
52
|
+
|
|
53
|
+ for (int i = 0; i < array.length; i++) {
|
|
54
|
+ int count = 0;
|
|
55
|
+ for (int j = 0; j < array.length; j++) {
|
|
56
|
+ if (array[i] == array[j]) {
|
|
57
|
+ count++;
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ }
|
|
61
|
+ if (count % 2 == 0) {
|
48
|
62
|
return array[i];
|
49
|
63
|
}
|
50
|
|
- }
|
51
|
|
- return array[array.length-1];
|
52
|
64
|
|
|
65
|
+ }
|
|
66
|
+ return null;
|
53
|
67
|
}
|
54
|
68
|
|
55
|
69
|
|
56
|
|
-
|
57
|
|
-
|
58
|
70
|
public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
|
59
|
71
|
|
60
|
72
|
Arrays.sort(array);
|