public boolean isMajorityElement(int[] nums, int target) {
int n = nums.length;
int i = 0, count = 0;
while (i < n && nums[i] != target) {
i++;
}
while (i < n && nums[i] == target) {
count++;
i++;
}
if (count > n / 2) {
return true;
}
return false;
}
LeetCode-Algorithms-[Easy]1150. 检查一个数是否在数组中占绝大多数
猜你喜欢
转载自blog.csdn.net/m0_37302219/article/details/105466744
今日推荐
周排行