Problem Statement
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
Examples:
s = "leetcode" return 0. s = "loveleetcode", return 2.
Note: You may assume the string contain only lowercase letters.
Solution:
class Solution:
def firstUniqChar(self, s: str) -> int:
if not s:
return -1
seen = {}
for i in range(len(s)):
if s[i] in seen:
seen[s[i]] = -1
else:
seen[s[i]] = i
for key in seen.keys():
if seen[key]>=0:
return seen[key]
return -1