LeetCode 387 First Unique Character in a String

LeetCode 387 First Unique Character in a String Problem

Download Code
class Solution(object):
    def firstUniqChar(self, s):
        """
        :type s: str
        :rtype: int
        """
        count_map = {}
        for c in s:
            count_map[c] = count_map.get(c, 0) + 1
        for i, c in enumerate(s):
            if count_map[c] == 1:
                return i
        return -1

    # def firstUniqChar(self, s):
    #     min([s.find(c) for c in string.ascii_lowercase if s.count(c)==1] or [-1])
Download First Unique Character in a String.py

List of all First Unique Character in a String problems

Leetcode 387 First Unique Character in a String problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.