码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 389. Find the Difference

时间:2019-04-05 19:52:13      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:etc   字符串   def   col   一个   The   pre   nbsp   obj   

多了一个字母,就两个字符串一减就得到多的那个.

但是字符串不能直接相减,所以就转成数字再减,最后再转回来.

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

 

Leetcode 389. Find the Difference

标签:etc   字符串   def   col   一个   The   pre   nbsp   obj   

原文地址:https://www.cnblogs.com/zywscq/p/10659522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!