Code Signal_缁冧範棰榑commonCharacterCount
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Code Signal_缁冧範棰榑commonCharacterCount相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/mon' title='mon'>mon
+= cli color between bsp ret def setGiven 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".
鎴戠殑瑙g瓟锛?/strong>
1 def commonCharacterCount(s1, s2): 2 sum = 0 3 for i in set(s1): 4 m = min(s1.count(i),s2.count(i)) 5 sum += m 6 return sum
鎯充簡鍗婂ぉ鎵嶆兂鍑烘潵鐢╯et锛岀煡璇嗛兘鐭ラ亾锛屼絾灏辨槸鎯充笉璧锋潵鐢紝杩樻槸缁冨緱灏戝晩
鑶滄嫓澶т浆锛?/span>
涓€浣嶇編鍥藉ぇ浣啓鐨?鎺掑悕闈犲墠鐨勫熀鏈兘鏄繖涔堝啓...)锛? def commonCharacterCount(s1, s2): return sum(min(s1.count(x), s2.count(x)) for x in set(s1))
以上是关于Code Signal_缁冧範棰榑commonCharacterCount的主要内容,如果未能解决你的问题,请参考以下文章