更新 Solution.java
parent
465b042d7e
commit
2277ac48a3
|
|
@ -49,7 +49,7 @@ public class Solution {
|
|||
}
|
||||
|
||||
|
||||
//哈希映射算法(Hash Mapping Algorithm)用于找出一个数组中的众数(majority element)
|
||||
//哈希映射算法(Hash Mapping Algorithm)用于找出一个数组中的众数(majority element)
|
||||
public static int majorityElement(int[] nums) {
|
||||
Map<Integer, Integer> map = new HashMap<>();
|
||||
// maxNum 表示元素,maxCount 表示元素出现的次数
|
||||
|
|
@ -64,7 +64,7 @@ public class Solution {
|
|||
}
|
||||
return maxNum;
|
||||
}
|
||||
//摩尔投票算法(Boyer-Moore Voting Algorithm)来找出数组中的众数
|
||||
//摩尔投票算法(Boyer-Moore Voting Algorithm)来找出数组中的众数
|
||||
public static int majorityElement1(int[] nums) {
|
||||
int candidate = nums[0], count = 1;
|
||||
for (int i = 1; i < nums.length; ++i) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue