class Solution:
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
dp=[0]*26
for i in range(len(s)):
dp[ord(s[i])-97]-=1
dp[ord(t[i])-97]+=1
for j in range(len(s),len(t)):
dp[ord(t[j])-97]+=1
return chr(dp.index(1)+97)
python leetcode 389. Find the Difference
最新推荐文章于 2025-12-10 14:25:37 发布
本文介绍了一种使用Python实现的高效算法,用于找出两个字符串中独有的字符。通过构建一个长度为26的数组来记录字母出现的差异,最终返回出现次数为1的字母。此算法适用于需要对比字符串差异的场景。

366

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



