Python Solution with O(n) time and space complexity


  • 0
    S
    class Solution(object):
        def firstUniqChar(self, s):
            """
            :type s: str
            :rtype: int
            """
            arr = [0] * len(s)
            for ch in s:
                arr[s.index(ch)] += 1
            for i in range(len(arr)):
                if( arr[i] == 1):
                    return i
            return -1
    

Log in to reply
 

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