Python Solution in O(n) using Dictionary


  • 0
    S
       def firstUniqChar(self, s):
           """
           :type s: str
           :rtype: int
           """
           hashmap={}
           for i in range(0,len(s)):
               hashmap[s[i]]=0
           for i in range(0,len(s)):
               hashmap[s[i]]+=1
           for i in range(0,len(s)):
               if hashmap[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.