【leetcode❤python】387. First Unique Character in a String

#-*- coding: UTF-8 -*-
class Solution(object):
    def firstUniqChar(self, s):
        s=s.lower()
        sList=list(s)
        numCdic={}
        for c in s:
            numCdic[c]=numCdic[c]+1 if c in numCdic else 1
        for i in range(len(sList)):
            if numCdic[sList[i]]==1:
                return i
 
        return -1
    
sol=Solution()
print sol.firstUniqChar('loveleetcode')

posted @ 2016-10-12 17:10  火金队长  阅读(227)  评论(0编辑  收藏  举报