Python O(N) solution

  • 0

    class Solution(object):
    def firstUniqChar(self, s):

        a=[]  #create a bucket for 26 characters
        for i in range(0,26):
        b = list(s)
        for i in b:
            a[ord(i)-ord('a')] += 1
        for (k,i) in enumerate(b):
            if a[ord(i)-ord('a')] == 1:
                return k
        return -1

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.