Compare commits
No commits in common. "338f74cb9edf2c4640dfc717d56e74d12eff17ac" and "ba7ac701a73afc9b4d337e94d72b165de61c76d8" have entirely different histories.
338f74cb9e
...
ba7ac701a7
|
@ -618,5 +618,3 @@ mod p1399_count_largest_group;
|
|||
mod p2338_count_the_number_of_ideal_arrays;
|
||||
|
||||
mod p2845_count_of_interesting_subarrays;
|
||||
|
||||
mod p1287_element_appearing_more_than_25_in_sorted_array;
|
|
@ -1,47 +0,0 @@
|
|||
use std::thread::current;
|
||||
|
||||
/**
|
||||
* [1287] Element Appearing More Than 25% In Sorted Array
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn find_special_integer(arr: Vec<i32>) -> i32 {
|
||||
let mut last = arr[0];
|
||||
let mut count = 1;
|
||||
let threshold = arr.len() / 4;
|
||||
|
||||
for &i in arr[1..].iter() {
|
||||
if last == i {
|
||||
count += 1;
|
||||
} else {
|
||||
last = i;
|
||||
count = 1;
|
||||
}
|
||||
|
||||
if count > threshold {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
last
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_1287() {
|
||||
assert_eq!(
|
||||
6,
|
||||
Solution::find_special_integer(vec![1, 2, 2, 6, 6, 6, 6, 7, 10])
|
||||
);
|
||||
assert_eq!(1, Solution::find_special_integer(vec![1, 1]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user