Easy Python solution


  • 0
    W
        def firstUniqChar(self, s):
            counter = {}
            for c in s:
                counter[c] = counter.get(c, 0) + 1
            
            for i, c in enumerate(s):
                if counter[c] == 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.