class Solution:
def firstUniqChar(self, s: str) -> int:
# main idea: dictionary.items() return in insertion order
# dictionary k:char, v: cnt
# find the first k where v == 1
# time O(N) space O(1) <= O(A) since Character has at most 26 types
if not s:
return -1
d = {}
for idx,ch in enumerate(s):
if ch not in d:
d[ch] = [1,idx]
else:
d[ch][0] += 1
for k,v in d.items():
if v[0] == 1:
return v[1]
return -1