标签:pre tco rac ring charindex leetcode == etc dict
用了一个字典
class Solution: def firstUniqChar(self, s: str) -> int: charIndexDict = {} for i in range(len(s)): if s[i] in charIndexDict: charIndexDict[s[i]] = -1 else: charIndexDict[s[i]] = i minIdx = float(‘inf‘) for char in charIndexDict: if charIndexDict[char] != -1: idx = charIndexDict[char] if idx < minIdx: minIdx = idx if minIdx == float(‘inf‘): return -1 return minIdx
[leetcode]First Unique Character in a String
标签:pre tco rac ring charindex leetcode == etc dict
原文地址:https://www.cnblogs.com/lautsie/p/12266776.html