Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf65cb47

Browse files
refactor 1150
1 parent2220d07 commitf65cb47

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
packagecom.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
publicclass_1150 {
294
publicstaticclassSolution1 {
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
publicbooleanisMajorityElement(int[]nums,inttarget) {
329
intfirstIndex =findFirstOccur(nums,target);
3310
intplusHalfIndex =firstIndex +nums.length /2;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp