Python dictionary


  • 0
    C
    class Solution(object):
        def firstUniqChar(self, s):
            """
            :type s: str
            :rtype: int
            """
            check={}
            for i,char in enumerate(s):
                if char not in check:
                    check[char]=[1,i]
                else:
                    check[char][0]=2
            index_min=len(s)
            for ind in check:
                if check[ind][0]==1:
                    index_min=min(index_min,check[ind][1])
            return index_min if index_min!=len(s) else -1
                    
    

Log in to reply
 

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