编程练习——第一个仅出现一次的字符
2017-08-03 21:36
295 查看
题目描述
在一个字符串(1<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置Python 1:
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
l=len(s)
if l<1 or l>10000:
return -1
temp=""
for i in range(l):
if s[i] not in s[i+1:] and s[i] not in temp:
return i
temp+=s[i]
return -1
Python 2:用count()函数
import sys
while True:
try:
line=sys.stdin.next().strip()
for i in line:
if line.count(i)==1:
print i
break
except:
break
相关文章推荐
- 【剑指Offer面试编程题】题目1283:第一个只出现一次的字符--九度OJ
- 【剑指Offer面试编程题】题目1283:第一个只出现一次的字符--九度OJ
- 编程艺术第十六~第二十章:全排列/跳台阶/奇偶调序/第一个只出现一次的字符,及一致性hash算法
- 数据结构练习(12)第一个只出现一次的字符
- 每天学习一点编程(5)(在一个字符串中找到第一个只出现一次的字符)
- 【编程题目】在一个字符串中找到第一个只出现一次的字符。如输入 abaccdeff,则输出 b。
- 【练习】在一个字符串中找到第一个只出现一次的字符。如输入abaccdeff,则输出b
- 剑指offer名企面试编程题:第一个只出现一次的字符
- (C++)剑指offer-34:第一个只出现一次的字符位置(时间空间效率的平衡)
- 在一个字符串中找到第一个只出现一次的字符。
- 第一个只出现一次的字符
- 剑指offer——第一个只出现一次的字符
- 请实现一个函数用来找出字符流中第一个只出现一次的字符
- 剑指offer 第一个只出现一次的字符
- 面试题 找到字符串中第一个只出现一次的字符
- 50、第一个只出现了一次的字符
- 剑指offer(36):第一个只出现一次的字符
- 第一个只出现一次的字符
- 在一个字符串中找到第一个只出现一次的字符
- 寻找字符串里第一个只出现过一次的字符