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

来源:互联网 发布:淘宝店铺发布宝贝草稿 编辑:程序博客网 时间:2024/05/22 19:46
def FirstNotRepeatingChar(string):hashStr = [0] * 256for c in string:hashStr[ord(c)] += 1for 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

0 0
原创粉丝点击