Problem
Given two strings, find the number of common characters between them.
Example
For s1 = "aabcc" and s2 = "adcaa", the output should becommonCharacterCount(s1, s2) = 3.
Strings have 3 common characters - 2"a"s and 1 "c".
Input/Output
[input] string s1
A string consisting of lowercase latin letters
a-z.Guaranteed constraints:
1 ≤ s1.length ≤ 15.[input] string s2
A string consisting of lowercase latin letters
a-z.Guaranteed constraints:
1 ≤ s2.length ≤ 15.[output] integer
Solution
두 개의 입력 문자열 중 공통된 문자열을 취하여 개수를 반환하는 형태입니다.
만약 s1이 문자 'a'를 2개, s2가 1개를 가지고 있는 형태라면, 최소값인 s2의 개수가 선택됩니다.
위와 같은 개념을 활용하면 문제를 해결할 수 있습니다.
'Programming > Algorithm' 카테고리의 다른 글
| [Algorithm] sortByHeight (0) | 2018.02.09 |
|---|---|
| [Algorithm] isLucky (0) | 2018.02.09 |
| [Algorithm] allLongestStrings (0) | 2018.02.09 |
| [Algorithm] matrixElementsSum (0) | 2018.02.08 |
| [Algorithm] almostIncreasingSequence (0) | 2018.02.08 |