A golang solution


  • 0
    N
    func majorityElement(nums []int) int {
        m := make(map[int]int)
    
    	for _, v := range nums {
    		m[v]++
    		if m[v] > len(nums) / 2 {
    			return v
    		}
    	}
    
    	return 0
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.