Yesoda Sanka 6 years ago
parent
commit
0a04263414
1 changed files with 24 additions and 12 deletions
  1. 24
    12
      src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java

+ 24
- 12
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java View File

@@ -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);