码迷,mamicode.com
首页 > 其他好文 > 详细

【剑指offer】第一个只出现一次的数

时间:2014-07-08 16:15:10      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:algorithm   面试题   python   unicode   

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

【剑指offer】第一个只出现一次的数,布布扣,bubuko.com

【剑指offer】第一个只出现一次的数

标签:algorithm   面试题   python   unicode   

原文地址:http://blog.csdn.net/shiquxinkong/article/details/37544659

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!