第一个只出现一次的字符

遍历的话若全部遍历则为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
                # 遍历不从前遍历,可以减少遍历次数
努力拼搏吧,不要害怕,不要去规划,不要迷茫。但你一定要在路上一直的走下去,尽管可能停滞不前,但也要走。
原文地址:https://www.cnblogs.com/wkhzwmr/p/15038296.html