Skip to content

Commit b6ba420

Browse files
refactor 1287
1 parent 221e7b0 commit b6ba420

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/main/java/com/fishercoder/solutions/_1287.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,13 @@
1818
public class _1287 {
1919
public static class Solution1 {
2020
public int findSpecialInteger(int[] arr) {
21-
for (int i = 0; i < arr.length - 1; ) {
22-
int count = 1;
23-
if (arr[i] == arr[i + 1]) {
24-
do {
25-
i++;
26-
count++;
27-
if (count > arr.length / 4) {
28-
return arr[i];
29-
}
30-
} while (i < arr.length - 1 && arr[i] == arr[i + 1]);
31-
} else {
32-
i++;
21+
int quarter = arr.length / 4;
22+
for (int i = 0; i < arr.length - quarter; i++) {
23+
if (arr[i] == arr[i + quarter]) {
24+
return arr[i];
3325
}
3426
}
35-
return arr[0];
27+
return -1;
3628
}
3729
}
3830
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy