Python solution


  • 0
    S
    class Solution(object):
        def firstUniqChar(self, s):
            """
            :type s: str
            :rtype: int
            """
            count_dict = {}
            # create char count
            for char in s:
                count_dict[char] = count_dict.get(char,0) +1
            # find char with count 1
            for i,char in enumerate(s):
                if count_dict[char] == 1:
                    return i
            return -1
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.