Notice
														
													
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
											            
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
													Tags
													
											
												
												- 금융문자분석경진대회
- 편스토랑 우승상품
- 프로그래머스
- ChatGPT
- github
- 편스토랑
- gs25
- PYTHON
- 프로그래머스 파이썬
- 맥북
- 파이썬
- hackerrank
- 데이콘
- SW Expert Academy
- Kaggle
- AI 경진대회
- leetcode
- 더현대서울 맛집
- Git
- Baekjoon
- 우분투
- 코로나19
- 자연어처리
- dacon
- 백준
- 캐치카페
- ubuntu
- programmers
- Real or Not? NLP with Disaster Tweets
- Docker
													Archives
													
											
												
												- Today
- Total
솜씨좋은장씨
[leetCode] 387. First Unique Character in a String (Python) 본문
								Programming/코딩 1일 1문제
								
							[leetCode] 387. First Unique Character in a String (Python)
솜씨좋은장씨 2020. 6. 15. 18:48728x90
    
    
  반응형
    
    
    
  
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
Examples:
s = "leetcode"
return 0.
s = "loveleetcode",
return 2.Solution
from collections import Counter
class Solution:
    def firstUniqChar(self, s: str) -> int:
        answer = -1
        s = list(s)
        cnt_dict = Counter(s)
        i = 0
        
        for word in s:
            if cnt_dict[word] == 1:
                answer = i
                break
            i = i + 1
                
        return answer


SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
| [leetCode] 20. Valid Parentheses (Python) (0) | 2020.06.17 | 
|---|---|
| [leetCode] 125. Valid Palindrome (Python) (0) | 2020.06.16 | 
| [leetCode] 88. Merge Sorted Array (Python) (0) | 2020.06.14 | 
| [leetCode] 136. Single Number (Python) (0) | 2020.06.13 | 
| [leetCode] 412. Fizz Buzz (Python) (2) | 2020.06.13 | 
								  Comments
								
							
						
					
                    
                
					
					
					
					
					
					
				 
						
					 
					 
													 
													 
													