leetcode python找不同

给两个字符串,第二个字符串是第一个字符串乱序后再随机插入一个字母在随机的位置,需要我们找到这个字母

输入:

s = "abcd"

t = "abcde"

输出:

e

class Solution:
    def findTheDifference(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: str
        """
        for i in s :
            t=t.replace(i,"",1)   #str.replace(old, new[, max])
        return t                  #max -- 可选字符串, 替换不超过 max 次
                                  
if __name__ == '__main__':
    s = Solution()
    res = s.findTheDifference("abcd","abcde" )
    print(res)
原文地址:https://www.cnblogs.com/hooo-1102/p/10797385.html