387. First Unique Character in a String
π© Easy
Question
s = "leetcode"
return 0.
s = "loveleetcode",
return 2.Code
from collections import Counter
def firstUniqChar(self, s: str) -> int:
for k, v in Counter(s).items():
# items() return the list with all dictionary keys with values
if v == 1:
return s.index(k)
return -1Python Counter Object
Last updated