Skip to content

Commit

Permalink
Create 1287_Element_Appearing_More_Than_25%_In_Sorted_Array.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhuzaima authored Dec 11, 2023
1 parent 9601824 commit 39519f1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 1287_Element_Appearing_More_Than_25%_In_Sorted_Array.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// id: 1287
// Name: Element Appearing More Than 25% In Sorted Array
// link: https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/
// Difficulty: Easy

class Solution {
public int findSpecialInteger(int[] arr) {
int c = arr.length / 4;

int current = arr[0];
int count = 0;
for (int i: arr) {
if (i == current) {
count++;
if (count > c) return i;
} else {
current = i;
count = 1;
}
}
return -1;
}
}

0 comments on commit 39519f1

Please sign in to comment.