1. 程式人生 > >Python:第一個只出現一次的字元

Python:第一個只出現一次的字元

牛客網上的劍指 offer的線上程式設計:

題目描述 在一個字串(1<=字串長度<=10000,全部由字母組成)中找到第一個只出現一次的字元,並返回它的位置
# -*- coding:utf-8 -*-
import time
'''
第一個只出現一次的字元
題目描述
在一個字串(1<=字串長度<=10000,全部由字母組成)中找到第一個只出現一次的字元,並返回它的位置
'''
class Solution:
    def FirstNotRepeatingChar(self, s):
        # write code here
        if s is '':
            return -1
        for i in range(len(s)):
            if s.count(s[i]) == 1:
                end = time.clock()
                return s.index(s[i])
        return None