题目:

找不同:给定两个字符串 s 和 t,它们只包含小写字母。  字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。  请找出在 t 中被添加的字母。

示例:

输入:
s = "abcd"
t = "abcde"

输出:
e

解释:
'e' 是那个被添加的字母。

思路:

思路较简单。

程序:

class Solution:
    def findTheDifference(self, s: str, t: str) -> str:
        if not s and t:
            return t 
        auxiliary1 = []
        auxiliary2 = []
        result = ''
        for index1 in range(len(s)):
            auxiliary1.append(s[index1])
        for index2 in range(len(t)):
            auxiliary2.append(t[index2])
        auxiliary1 = sorted(auxiliary1)
        auxiliary2 = sorted(auxiliary2)
        auxiliary1.append('')
        for index3 in range(len(auxiliary1)):
            if auxiliary1[index3] != auxiliary2[index3]:
                result += auxiliary2[index3]
                break
        return result

  

相关文章:

  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
相关资源
相似解决方案