【剑指offer】面试题35:第一个数字只出现一次

def FirstNotRepeatingChar(string):
	hashStr = [0] * 256
	for c in string:
		hashStr[ord(c)] += 1
	for c in string:
		if hashStr[ord(c)] == 1:
			return c

这里说下ord, 能够作为atoi来用。功能是若给定的參数是一个长度为1的字符串,那么若參数是Unicode对象。则返回相应的整数。若为8-bit的string,则返回相应的值。

python的帮助文档里举例:

For example, ord('a') returns the integer 97, ord(u'u2020') returns 8224

版权声明:本文博主原创文章。博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/blfshiye/p/4887416.html