第一个只出现一次的字符
时间:2021-07-21 17:39:49
收藏:0
阅读:0
遍历的话若全部遍历则为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
# 遍历不从前遍历,可以减少遍历次数
评论(0)