1/20/2021

[LeetCode] 387. First Unique Character in a String

 Problem : https://leetcode.com/problems/first-unique-character-in-a-string/


class Solution:
    def firstUniqChar(self, s: str) -> int:
        counter = Counter(s)
        
        for i, n in enumerate(s):
            if counter[n] == 1: return i
        
        return -1

No comments:

Post a Comment