参考回答:
def first_not_repeating_char(string):if not string:return -1resultDict = {}for k, s in enumerate(string):resultDict [s] = [resultDict [s][0] + 1,k] if resultDict .get(s) else [1,k]pos = len(string)ret = Nonefor x in resultDict :if resultDict [x][0] ==1 and resultDict [x][1] <pos:pos = resultDict [x][1]ret = (x,pos)return ret
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)