题解 | #单词字符# | Golang
单词字符
https://www.nowcoder.com/practice/a64958131b094faba2adf52a4b131848
package main
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return char字符型
*/
func character( s string ) byte {
hash_table := map[byte]int{}
cnt := -1
var res byte
for _,val := range s {
if _, ok := hash_table[byte(val)];ok {
hash_table[byte(val)]++
} else {
hash_table[byte(val)] = 1
}
if hash_table[byte(val)] >= cnt {
res = byte(val)
cnt = hash_table[res]
}
}
return res
}
查看16道真题和解析