I wrote a solution to first-unique-character-in-a-string:
Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1.
If there is better way for me to build the dictionary
seems? and find the first key when
value is 1 and
index is lowest?
def firstUniqChar(string) -> int: seems = dict() index = len(string) c = '' for i, char in string: if char not in seems: seems.setdefault(char, (i,1)) else: seems[char] = (seems[char], seems[char] + 1) for k, value in seems.items(): if value == 1 and value < index: index = value c = k return index if c else -1