Problem List

Majority Element

March 02, 2025Go array, hash table, sorting, counting, divide and conquer

Go Solution
func majorityElement(nums []int) int {
    hashMap := make(map[int]int)
   for _,num := range nums {
        hashMap[num]++
        if hashMap[num] > len(nums)/2 {
            return num
        }
   } 
   return 0
}
LeetCode Problem Link