美文网首页
第一个只出现一次的字符

第一个只出现一次的字符

作者: 九日火 | 来源:发表于2021-01-09 15:04 被阅读0次
class Solution:
    def FirstNotRepeatingChar(self, s):
        if s == None or len(s) <= 0:
            return -1

        alphat = {}
        alist = list(s)
        for i in alist:
            if i not in alphat.keys():
                alphat[i] == 0
            alphat[i] += 1
        for i in alphat:
            if alphat[i] == 1:
                return alphat[i]

        return -1
package main


func Count(str string) int {
    bytes := []byte(str)
    m := make(map[byte]int)
    for _, v := range bytes {
        m[v]++
    }

    for i, v := range bytes {
        if m[v] == 1 {
            return v
        }
    }
    return -1
}

相关文章

网友评论

      本文标题:第一个只出现一次的字符

      本文链接:https://www.haomeiwen.com/subject/hqzaoktx.html