10. Given two strings, find the number of common characters between them.
Example)
For s1 = "aabcc" and s2 = "adcaa", the output should be commonCharacterCount(s1, s2) = 3.
Strings have 3 common characters - 2 "a"s and 1 "c".
1
2
3
4
5
6
|
def commonCharacterCount(s1, s2):
count = 0
common_ch = set(s1) & set(s2)
for i in common_ch:
return count
|
1
2
3
4
5
|
# solution code
def commonCharacterCount(s1, s2):
return sum(com)
|
'Programming > Python' 카테고리의 다른 글
[python] codeSignal 문제풀이 (9) (0) | 2020.01.10 |
---|---|
[python] codeSignal 문제풀이 (7~8) (0) | 2020.01.08 |
[python] codeSignal 문제풀이 (4~6) (0) | 2020.01.07 |
[python] codeSignal 문제풀이 (1~3) (0) | 2020.01.07 |