387_First Unique Character in a String
s = "leetcode"
return 0.
s = "loveleetcode",
return 2.Solution 1: brute force
def firstUniqChar(s):
"""
:type s: str
:rtype: int
"""
for i in range(len(s)):
c = s[i]
if s.count(c) == 1: # can write count as a helper function if needed
return i
return -1Solution 2: Use dictionary
Last updated