The first character to appear only once.

Title Description

Find the first character that appears only once in a string (0< = string length < = 10000, all made up of letters) and return its position, if not – 1 (case sensitive)

thinking

Traversing the string, find the value of the first count count 1 and return its subscript value.

Answer

class Solution:
    def FirstNotRepeatingChar(self, s):
        # write code here
        if not s or len(s)>10000:
            return -1
        else:
            for i in s:
                if s.count(i) == 1:
                    return s.index(i)

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *