leetcode之Find the Difference

原创 2016年08月30日 00:13:15

这题是找出2个字符串不同的部分,只是多了一个字母。注意顺序有可能会错乱。使用collections包里面的Counter模块轻松搞定。

from collections import Counter
class Solution(object):
    def findTheDifference(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: str
        """
        if s == '':
            return t
        a = Counter(s)
        b = Counter(t)
        for i in b.keys():
            if a[i] != b[i]:
                return i
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

关于LeetCode中Find the Difference一题的理解

题目如下: Given two strings s and t which consist of only lowercase letters. String t is generat...

LeetCode笔记:389. Find the Difference

在两个字符串中找出唯一多出的那个字母

LeetCode 389. Find the Difference

题意两个字符串s,t,都是小写字母,t由s中的字符和新增的一个字母随机排列组合而成,找出新增的字符!思路最直接的思路是HashMap,根据字符串s建立一个HashMap,key是字母,value是字母...

leetcode389. Find the Difference

389. Find the DifferenceGiven two strings s and t which consist of only lowercase letters.String t i...

leetcode算法——389. Find the Difference(基于JAVA)

Given two strings s and t which consist of only lowercase letters. String t is generated by random s...

【LeetCode】389 Find the Difference(java)

原题Given two strings s and t which consist of only lowercase letters.String t is generated by random ...

[LeetCode]389. Find the Difference(找不同)

389. Find the DifferenceGiven two strings s and t which consist of only lowercase letters. String t...

LeetCode之Find the Difference

1、题目 Given two strings s and t which consist of only lowercase letters. String t is generate...

[LeetCode]242.Valid Anagram&383. Ransom Note&389. Find the Difference

242.Valid Anagram 383. Ransom Note 389. Find the Difference

【Leetcode】389. Find the Difference

方法一: 思路: 利用一个HashMap,先统计s字符串中每个字符出现的次数,然后遍历t字符串,若该字符未包含在HashMap中或出现次数等于0,立即返回该字符,否则,该字符出现的次数减一。 pub...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)