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
- 우분투
- 코로나19
- PYTHON
- 데이콘
- 프로그래머스 파이썬
- hackerrank
- 파이썬
- 편스토랑
- ChatGPT
- Baekjoon
- 맥북
- SW Expert Academy
- 캐치카페
- Git
- Real or Not? NLP with Disaster Tweets
- 더현대서울 맛집
- Docker
- ubuntu
- gs25
- AI 경진대회
- github
- 편스토랑 우승상품
- 백준
- leetcode
- 프로그래머스
- 금융문자분석경진대회
- Kaggle
- programmers
- dacon
- 자연어처리
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
'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