mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-06-04 02:21:15 +08:00
routine
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
func majorityElement(nums []int) int {
|
||||
a, s := nums[0], 1
|
||||
for i := 1; i < len(nums); i++ {
|
||||
if a == nums[i] {
|
||||
s++
|
||||
continue
|
||||
}
|
||||
s--
|
||||
if s == 0 {
|
||||
a = nums[i]
|
||||
s = 1
|
||||
}
|
||||
}
|
||||
return a
|
||||
}
|
||||
Reference in New Issue
Block a user