Element Appearing More Than 25% In Sorted Array
给一个sorted数组, 返回里面大于25%长度的数. 这个我直接count的…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Solution { public int findSpecialInteger(int[] arr) { int t = 0; int count = 0; for(int n : arr) { if(t == n) { count++; } else { t = n; count = 1; } if(count > arr.length / 4) return n; } return -1; } } |