原题
给出两个字符串,只有一处不同,一个字符串比两一个多一个字符,找出这个字符
样例
Input:
s = "abcd"
t = "abcde"
Output:
e
Explanation:
'e' is the letter that was added.
解题思路
- 合并两个字符串,题目转化为寻找单身狗
完整代码
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
temp = 0
for char in s + t:
temp = temp ^ ord(char)
return chr(temp)