python leetcode 389. Find the Difference

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)

猜你喜欢

转载自blog.csdn.net/Neekity/article/details/84583612