Skip to content

Commit 39519f1

Browse files
authored
Create 1287_Element_Appearing_More_Than_25%_In_Sorted_Array.java
1 parent 9601824 commit 39519f1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// id: 1287
2+
// Name: Element Appearing More Than 25% In Sorted Array
3+
// link: https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/
4+
// Difficulty: Easy
5+
6+
class Solution {
7+
public int findSpecialInteger(int[] arr) {
8+
int c = arr.length / 4;
9+
10+
int current = arr[0];
11+
int count = 0;
12+
for (int i: arr) {
13+
if (i == current) {
14+
count++;
15+
if (count > c) return i;
16+
} else {
17+
current = i;
18+
count = 1;
19+
}
20+
}
21+
return -1;
22+
}
23+
}

0 commit comments

Comments
 (0)