LeetCode-Algorithms-[Easy]1150. 检查一个数是否在数组中占绝大多数

1150. 检查一个数是否在数组中占绝大多数

	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;
	}
发布了272 篇原创文章 · 获赞 7 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/m0_37302219/article/details/105466744