First Unique Character Python Solution String Slicing


  • 0
    S
    class Solution(object):
        def firstUniqChar(self, s):
            """
            :type s: str
            :rtype: int
            """
            
            if (s == ""):
                return -1
    
            res = -1
            alreadyAppearedChars = []
            for i in range(0, len(s)):
                var = s[i]
                restOfTheString = s[i + 1:]
                if (restOfTheString.find(var) != -1):
                    alreadyAppearedChars.append(s[i])
                    continue
                else:
                    if (s[i] not in alreadyAppearedChars):
                        return i
                    else:
                        continue
    
            return res
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.