Skip to content

Commit f65cb47

Browse files
refactor 1150
1 parent 2220d07 commit f65cb47

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

src/main/java/com/fishercoder/solutions/_1150.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,10 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 1150. Check If a Number Is Majority Element in a Sorted Array
5-
*
6-
* Given an array nums sorted in non-decreasing order, and a number target, return True if and only if target is a majority element.
7-
* A majority element is an element that appears more than N/2 times in an array of length N.
8-
*
9-
* Example 1:
10-
* Input: nums = [2,4,5,5,5,5,5,6,6], target = 5
11-
* Output: true
12-
* Explanation:
13-
* The value 5 appears 5 times and the length of the array is 9.
14-
* Thus, 5 is a majority element because 5 > 9/2 is true.
15-
*
16-
* Example 2:
17-
* Input: nums = [10,100,101,101], target = 101
18-
* Output: false
19-
* Explanation:
20-
* The value 101 appears 2 times and the length of the array is 4.
21-
* Thus, 101 is not a majority element because 2 > 4/2 is false.
22-
*
23-
* Note:
24-
* 1 <= nums.length <= 1000
25-
* 1 <= nums[i] <= 10^9
26-
* 1 <= target <= 10^9
27-
**/
283
public class _1150 {
294
public static class Solution1 {
30-
/**credit: https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array/discuss/358130/Java-just-one-binary-search-O(logN))-0ms-beats-100*/
5+
/**
6+
* credit: https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array/discuss/358130/Java-just-one-binary-search-O(logN))-0ms-beats-100
7+
*/
318
public boolean isMajorityElement(int[] nums, int target) {
329
int firstIndex = findFirstOccur(nums, target);
3310
int plusHalfIndex = firstIndex + nums.length / 2;

0 commit comments

Comments
 (0)