Python simple O(n) solution

  • 0
    class Solution(object):
        def firstUniqChar(self, s):
            :type s: str
            :rtype: int
            dict= {}
            for i in s:
                if(dict.get(i)== None):
                    dict[i]= 1
                else: dict[i]+=1
            for i in range(len(s)):
                if(dict[s[i]]== 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.