python比较两个字符串中字母一致_Leetcode练习(Python):第389题:找不同:给定两个字符串 s 和 t,它们只包含小写字母。 字符串 t 由字符串 s 随机重排,然后在随机位置添...

题目:

找不同:给定两个字符串 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

原文链接:https://www.cnblogs.com/zhuozige/p/12983221.html

本文来自网络,不代表手讯网立场。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值