[34.] Offer to prove safety first character appears only once realized python

Title Description

In one string (0 <= length of the string <= 10000, all of the alphabet) find a first character appears only once, and returns to its position, or -1 if not (case-sensitive).

example:

Input:
Google
the corresponding output would be:
4

Code

# -*- 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)
        
Published 99 original articles · won praise 6 · views 3962

Guess you like

Origin blog.csdn.net/weixin_42247922/article/details/104012497