티스토리 뷰
Count the number of Duplicates
Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.
Example
"abcde" -> 0 # no characters repeats more than once
"aabbcde" -> 2 # 'a' and 'b'
"aabBcde" -> 2 # 'a' occurs twice and 'b' twice (bandB)
"indivisibility" -> 1 # 'i' occurs six times
"Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice
"aA11" -> 2 # 'a' and '1'
"ABBA" -> 2 # 'A' and 'B' each occur twice
문자열에서 case insensitive하게 중복 문자가 몇개 존재하는지 구하는 문제, 나는 재귀함수를 이용해서 풀었다
def duplicate_count(text):
text = text.lower()
if text=='':
return 0
elif text[0] in text[1:]:
return 1+duplicate_count(text[1:].replace(text[0],''))
else :
return duplicate_count(text[1:])
'개발 > Quiz' 카테고리의 다른 글
[codewars] Pete, the baker (0) | 2017.12.20 |
---|---|
[codewars] Sort the odd (0) | 2017.12.17 |
Take a Number And Sum Its Digits Raised To The Consecutive Powers And ....¡Eureka!! (0) | 2017.12.11 |
Complementary DNA (0) | 2017.12.11 |
Format a string of names like 'Bart, Lisa & Maggie'. (0) | 2017.12.10 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- PYTHON
- 개봉기
- codewars
- conda
- introduction to algorithms third edtion
- 치닝디핑
- Introduction to algorithms
- 멜킨스포츠
- CHUWI HI8
- 하스스톤
- 연습문제
- anaconda
- 마스터킹
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함