题目:
题解:
class Solution:
def firstUniqChar(self, s: str) -> int:
position = dict()
q = collections.deque()
n = len(s)
for i, ch in enumerate(s):
if ch not in position:
position[ch] = i
q.append((s[i], i))
else:
position[ch] = -1
while q and position[q[0][0]] == -1:
q.popleft()
return -1 if not q else q[0][1]