第一个只出现一次的字符

题目描述
在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1(需要区分大小写).

# -*- coding:utf-8 -*-
class Solution:
    def FirstNotRepeatingChar(self, s):
        if len(s)==0:
            return -1
        dic = {}
        for i in range(len(s)):
            if s[i] not in dic:
                dic[s[i]] = i
            else:
                dic[s[i]] = 10001
        return -1 if min(dic.values())==10001 else min(dic.values())
posted @ 2019-03-02 17:51  bernieloveslife  阅读(76)  评论(0编辑  收藏  举报