<filename>First Unique Character in a String.py<gh_stars>0
class Solution:
    def firstUniqChar(self, s):
        table = {}
        for ele in s:
            table[ele] = table.get(ele, 0) + 1
        # for i in range(len(s)):
        #     if table[s[i]] == 1:
        #         return i
        for ele in s:
            if table[ele] == 1:
                return s.index(ele)
        return -1

if __name__ == '__main__':
    s = 'leetcode' # output 0
    #s = 'loveleetcode' # output 2
    #s = 'llee' # output -1
    print(Solution().firstUniqChar(s))
<filename>First Unique Character in a String.py<gh_stars>0
class Solution:
    def firstUniqChar(self, s):
        table = {}
        for ele in s:
            table[ele] = table.get(ele, 0) + 1
        # for i in range(len(s)):
        #     if table[s[i]] == 1:
        #         return i
        for ele in s:
            if table[ele] == 1:
                return s.index(ele)
        return -1

if __name__ == '__main__':
    s = 'leetcode' # output 0
    #s = 'loveleetcode' # output 2
    #s = 'llee' # output -1
    print(Solution().firstUniqChar(s))
# for i in range(len(s)): #     if table[s[i]] == 1: #         return i # output 0 #s = 'loveleetcode' # output 2 #s = 'llee' # output -1