Problem:
Given a string, find the number of different characters in it.
Example
For s = "cabca", the output should be
differentSymbolsNaive(s) = 3.
There are 3 different characters a, b and c.
-Summary-
1. Create a temporary set variable to not have a duplicate value
2. Using for loop, if the character is already in the set, we skip and continue.
If the first character faced, we add in to set and increase the count.
3. return with count
사람들이 올린 답을 보니, 다음의 한줄로 가능하였다. 오늘도 더 간단한 코드를 배운다.
return len(set(s))
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]
'CodeSignal > Arcade' 카테고리의 다른 글
CodeSignal [38/60] growingPlant (0) | 2020.05.25 |
---|---|
CodeSignal [37/60] arrayMaxConsecutiveSum (0) | 2020.05.25 |
CodeSignal [35/60] firstDigit (0) | 2020.05.25 |
CodeSignal [34/60] extractEachKth (0) | 2020.05.24 |
CodeSignal [33/60] stringsRearrangement (1) | 2020.05.23 |
댓글