题解 | #单词字符#

单词字符

https://www.nowcoder.com/practice/a64958131b094faba2adf52a4b131848

package main
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param s string字符串 
 * @return char字符型
*/
func character( s string ) byte {
    // write code here
    hash := make(map[byte]int)
    count := 0
    var res byte;
    str := []byte(s)
    for _,v := range str{
        hash[v] += 1
        if hash[v] > count {
            count = max(count,hash[v])
            res = v
        }
    }
    return res
}
func max(n1,n2 int) int {
    if n1 > n2 {
        return n1
    }else {
        return n2
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务