Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594

导航

<2025年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

留言簿(9)

文章分类(1191)

文章档案(594)

搜索

  •  

积分与排名

  • 积分 - 112758
  • 排名 - 221

最新评论

由字符串s打乱字符再增加一个字符构成字符串t,求加入的字符,两个字符串分别sort然后按位对比


 1 #389
 2 #Runtime: 18 ms (Beats 62.90%)
 3 #Memory: 13.3 MB (Beats 57.11%)
 4 
 5 class Solution(object):
 6     def findTheDifference(self, s, t):
 7         """
 8         :type s: str
 9         :type t: str
10         :rtype: str
11         """
12         s = sorted(s)
13         t = sorted(t)
14         for i in xrange(len(s)):
15             if s[i] != t[i]:
16                 return t[i]
17         return t[-1]