版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mygodhome/article/details/85270161
Given two strings s and t which consist of only lowercase letters.
String t is generated by random shuffling string s and then add one more letter at a random position.
Find the letter that was added in t.
Example:
Input: s = "abcd" t = "abcde" Output: e Explanation: 'e' is the letter that was added.
class Solution:
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
stra='abcdefghijklmnopqrstuvwxyz'
for c in stra:
if len(s.split(c))!=len(t.split(c)):
return c
Reference:
http://www.runoob.com/python3/python3-string-split.html
不知道leetcode怎么了,在set集合的时候报错,但在python IDE可以。
return set(s).symmetric_difference(t)