mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 09:23:19 +08:00
Update 0167、0169
This commit is contained in:
@ -6,11 +6,12 @@ func majorityElement(nums []int) int {
|
||||
for i := 0; i < len(nums); i++ {
|
||||
if count == 0 {
|
||||
res, count = nums[i], 1
|
||||
}
|
||||
if nums[i] == res {
|
||||
count++
|
||||
} else {
|
||||
count--
|
||||
if nums[i] == res {
|
||||
count++
|
||||
} else {
|
||||
count--
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
|
Reference in New Issue
Block a user