Python 5 Lines : O(n) time + O(n) Space


  • 0
    A
    def firstUniqChar(self, s):
            d = Counter(s)
            for i in xrange( len(s) ):
                if d[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.