파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 8. 16. 23:45

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

 

First Unique Character in a String - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

한동안 hard만 나오더니 요즘은 easy 가 가끔 나오네 ㅎㅎ
문제를 좀 잘 못봤음.. 결국 hash 개념으로 접근하면 쉽게 풀림

class Solution:
    def firstUniqChar(self, s: str) -> int:        
        cnt = collections.Counter(s)
        
        for i, ch in enumerate(s):
            if cnt[ch] == 1:
                return i
        
        return -1
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.08.18
Today's Challenge  (0) 2022.08.17
Today's Challenge  (0) 2022.08.15
Today's Challenge  (0) 2022.08.14
Today's Challenge  (0) 2022.08.13
Comments