209. First Unique Character in a String
Description:
Find the first unique character in a given string. You can assume that there is at least one unique character in the string.
Example
For “abaccdeff”, return ‘b’.
Code:
class Solution:
"""
@param str: str: the given string
@return: char: the first unique character in a given string
"""
def firstUniqChar(self, str):
# Write your code here
dict = {}
for i in str:
dict[i] = dict[i]+1 if i in dict else 1
for i in range(len(str)):
if dict[str[i]] == 1:
return str[i]