第一个只出现一次字符的位置 牛客网 剑指Offer

mac2022-06-30  115

第一个只出现一次字符的位置  牛客网 剑指Offer

题目描述在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1(需要区分大小写) class Solution: #run:28ms memory:5732k def FirstNotRepeatingChar(self, s): if len(s) <= 0: return -1 hash_dict = {} for i in s: if i in hash_dict: hash_dict[i] += 1 else: hash_dict[i] = 1 for j in s: if hash_dict[j] == 1: return s.index(j)

 

转载于:https://www.cnblogs.com/vercont/p/10210357.html

最新回复(0)