Python nice one, time O(n) time O(1) space


  • 0
    Z

    class Solution(object):
    def firstUniqChar(self, s):
    """
    :type s: str
    :rtype: int
    """
    a=[0]*((ord('z')-ord('a'))+1)
    for i in range(len(s)):
    a[ord(s[i])-ord('a')]+=1
    for i in range(len(s)):
    if a[ord(s[i])-ord('a')]==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.