这题是找出2个字符串不同的部分,只是多了一个字母。注意顺序有可能会错乱。使用collections包里面的Counter模块轻松搞定。
from collections import Counter
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
if s == '':
return t
a = Counter(s)
b = Counter(t)
for i in b.keys():
if a[i] != b[i]:
return i