go实现

package main

/**
 * 
 * @param numbers int整型一维数组 
 * @return int整型
*/
func MoreThanHalfNum_Solution( numbers []int ) int {
    // write code here
    if len(numbers) == 0 {
        return 0
    }

    most := numbers[0]
    count := 0

    for _, x := range numbers {
        if x == most {
            count++
        }else{
            count--
        }
        if count <=0 {
            count = 1
            most = x
        }
    }


    count = 0
    for _, x := range numbers {
        if x == most {
            count++
        }
    }

    if count > len(numbers)/2 {
        return most
    }
    return 0
}