题目传送门:Find the Difference
题意:给两个字符串s,t t串是由s串中的字母组成,并额外添加了1个或多个字母,找出这些额外的字母.
思路:把t串扔set里先去重,然后构造两个个字典,key为set里的字母,分别统计s,t的字母的次数,然后遍历set输出字母出现次数之差即可.
题目描述:
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.
Python代码:
1 | class Solution(object): |