题目描述
在一个字符串(1<=字符串长度<=10000,全部由大小写字母组成)中找到第一个只出现一次的字符,并返回它的位置
python实现:
# -*- coding:utf-8 -*-
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
n = len(s)
if n==0:
return -1
from collections import Counter
hashCnt = Counter(s)
for i in range(n):
if hashCnt[s[i]]==1:
return i
return -1