leetcode_gym/_code/strings/firstNonRepeating.py

12 lines
249 B
Python
Raw Permalink Normal View History

s = "eleetcode"
def firstUniqChar(s):
visited = set()
for i in range(len(s)):
if s[i] not in visited:
visited.add(s[i])
if s.count(s[i]) == 1:
return i
return -1
print( firstUniqChar(s) )