Simple Python Solution


  • 0
    M
    def firstUniqChar(self, s):
        """
        :type s: str
        :rtype: int
        """
        chars = [0]*26
        shift = ord('a')
        for i in xrange(len(s)):
            chars[ord(s[i]) - shift] += 1
        
        for i in xrange(len(s)):
            if chars[ord(s[i]) - shift] == 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.