第一个只出现一次的字符

遍历的话若全部遍历则为N,若遍历k次,则为k

class Solution:
    """
    @param str: str: the given string
    @return: char: the first unique character in a given string
    """
    def firstUniqChar(self, str):
        # Write your code here
        for i in str:
            b = str.count(i) # 时间复杂度太大了
            if b == 1:
                return i
                # 遍历不从前遍历,可以减少遍历次数
posted @ 2021-07-21 10:10  索匣  阅读(29)  评论(0编辑  收藏  举报