Python O(n) Solution Passed 100%


  • 0
    L
    class Solution(object):
        def firstUniqChar(self, s):
            """
            :type s: str
            :rtype: int
            """
            d = dict()
            
            for i in range(len(s)):
                if d.setdefault(s[i],[]) or True:
                    d[s[i]].append(i)
            
            for i in range(len(s)):
                if len(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.