给定两个字符串 s 和 t,它们只包含小写字母。
字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
请找出在 t 中被添加的字母。
示例:
输入:
s = "abcd"
t = "abcde"
输出:
e
解释:
'e' 是那个被添加的字母。
用一个字典来保存每个字母出现的次数。 循环第二个字符串的时候,判断该字母出现在第一个字典中的情况,如果没有出现,那么该字母就是目标,如果出现,那么先减1,如果是0就删除,这样第二个次数多的时候就会找不到了。
fox64194167 ©著作权
给定两个字符串 s 和 t,它们只包含小写字母。
字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
请找出在 t 中被添加的字母。
示例:
输入:
s = "abcd"
t = "abcde"
输出:
e
解释:
'e' 是那个被添加的字母。
用一个字典来保存每个字母出现的次数。 循环第二个字符串的时候,判断该字母出现在第一个字典中的情况,如果没有出现,那么该字母就是目标,如果出现,那么先减1,如果是0就删除,这样第二个次数多的时候就会找不到了。
上一篇:python 使用 redis
下一篇:python 正则表达式
1、题目Given two stringssandtwhich consist of only lowercase letters.Stringtis generated by random shuffling stringsand the
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M