一度だけのpythonを実現し、安全第一の文字が表示されることを証明する[34]オファー

タイトル説明

1つの文字列(0 <=文字列<= 10000、アルファベットのすべての長さ)最初の文字を見つけることが一度だけ表示され、その位置に戻る、または-1でない場合(大文字と小文字を区別)で。

用例:

入力:
Googleは
、対応する出力は次のようになります。
4

コード

# -*- coding:utf-8 -*-
class Solution:
    def FirstNotRepeatingChar(self, s):
        # write code here
        if s == '':
            return -1
        else:
            a = list(s)
            res = []
            for i in a:
                count = 0
                for j in a:
                    if i == j:
                        count +=1
                res.append(count)
            return res.index(1)
        
公開された99元の記事 ウォンの賞賛6 ビュー3962

おすすめ

転載: blog.csdn.net/weixin_42247922/article/details/104012497