1. 程式人生 > >Leetcode 389. Find the Difference

Leetcode 389. Find the Difference

return diff sel 回來 字符串 tco object leet ret

多了一個字母,就兩個字符串一減就得到多的那個.

但是字符串不能直接相減,所以就轉成數字再減,最後再轉回來.

class Solution(object):
    def findTheDifference(self, s, t):
        return chr(sum(map(ord,t))-sum(map(ord,s)))

Leetcode 389. Find the Difference