1. 程式人生 > >python leetcode 389. Find the Difference

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)