You are given two strings s and t.
String t is generated by random shuffling string s and then add one more letter at a random position.
Return the letter that was added to t.
Example 1:
Input: s = "abcd", t = "abcde" Output: "e" Explanation: 'e' is the letter that was added.
Example 2:
Input: s = "", t = "y" Output: "y"
Constraints:
0 <= s.length <= 1000t.length == s.length + 1sandtconsist of lowercase English letters.
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
list1 = []
list2 = []
for i in s:
list1.append(i)
for j in t:
list2.append(j)
for k in list1:
list2.remove(k)
return list2[0]
本文介绍了一种算法,用于解决给定字符串s被随机打乱并添加一个字母后,确定新增字符的问题。通过实例和代码实现,帮助读者理解如何在已知s和t的情况下找到t中新增的字符。
350

被折叠的 条评论
为什么被折叠?



