https://app.codesignal.com/interview-practice/task/uX5iLwhc6L5ckSyNC/description
✔️문제 요약
1.주어진 문자열에서, 첫번째로 등장한 단하나의 문자를 출력한다.
2.주어진 문자열에 혼자 등장한 문자가 없으면, '_'을 출력
✔️풀이 방법
1.array 이지만, 이 문제를 보자마자 Counter 함수를 떠올렸다. 파이썬에서 가끔 전처리를 하며 해당함수를 쓰는데
익숙해지면 좋을 것 같아서 나는 Counter 함수를 통해 풀었다.
from collections import Counter
def solution(s):
dic=Counter(s).most_common()
for key, value in dic:
if value == 1:
return key
return '_'
✔️고찰
-리스트로 풀게된다면, index를 이용해서 풀었을 것 같다.
'코딩테스트 > 코딩테스트 Python' 카테고리의 다른 글
[CodeSignal] isTreeSymmetric (Python) (0) | 2022.10.07 |
---|---|
[CodeSignal] sudoku2 (Python) (1) | 2022.09.27 |
[CodeSignal] findProfession (Python) (0) | 2022.09.19 |
[CodeSignal] rotateImage (Python) (0) | 2022.09.14 |
[CodeSiganl] missingNumber (Python) (0) | 2022.09.07 |
댓글