solution for python (98ms)


  • 0
    W

    class Solution(object):
    def firstUniqChar(self, s):
    """
    :type s: str
    :rtype: int
    """
    s=s.lower()
    list1=[] % used to save the numbers of each element
    index1=[] %used to save the index of the element whose occurance number is 1
    for each in set(s):
    c=s.count(each)
    list1.append(c)
    if c==1:
    i=s.index(each)
    index1.append(i)
    if 1 not in list1:
    return -1
    else:
    return min(index1)


Log in to reply
 

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