代码拉取完成,页面将自动刷新
# Time: O(n)
# Space: O(1)
import operator
import collections
from functools import reduce
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
return chr(reduce(operator.xor, map(ord, s), 0) ^ reduce(operator.xor, map(ord, t), 0))
def findTheDifference2(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
t = list(t)
s = list(s)
for i in s:
t.remove(i)
return t[0]
def findTheDifference3(self, s, t):
return chr(reduce(operator.xor, map(ord, s + t)))
def findTheDifference4(self, s, t):
return list((collections.Counter(t) - collections.Counter(s)))[0]
def findTheDifference5(self, s, t):
s, t = sorted(s), sorted(t)
return t[-1] if s == t[:-1] else [x[1] for x in zip(s, t) if x[0] != x[1]][0]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。