728x90
Given a string, find the number of different characters in it.
Example
For s = "cabca"
, the output should bedifferentSymbolsNaive(s) = 3
.
There are 3
different characters a
, b
and c
.
Input/Output
- [execution time limit] 20 seconds (swift)
- [input] string sGuaranteed constraints:
3 ≤ s.length ≤ 1000
. - A string of lowercase English letters.
- [output] integer
설명
주어지는 문자열에서 서로다른 문자의 수를 리턴하라
풀이
Set의 중복 요소를 허용하지 않는 특성을 이용하여 해결
func differentSymbolsNaive(s:String) -> Int {
let arr = s.map{$0}
return Set(arr).count
}
728x90
'알고리즘 > 코드시그널' 카테고리의 다른 글
Codesignal - evenDigingsOnly (0) | 2021.05.03 |
---|---|
Codesignal - digitDegree (0) | 2021.05.02 |
Codesignal - depositProfit (0) | 2021.05.02 |
Codesignal - commonCharacterCount (0) | 2021.05.01 |
Codesignal - Circle of Numbers (0) | 2021.05.01 |
댓글