leetcode 299. Bulls and Cows

来源:互联网 发布:淘宝 一件代发 编辑:程序博客网 时间:2024/06/06 01:54
from collections import Counterclass Solution(object):    def getHint(self, secret, guess):        """        :type secret: str        :type guess: str        :rtype: str        """        """        https://discuss.leetcode.com/topic/28466/python-3-lines-solution        """        a,b = Counter(secret),Counter(guess)        bull_count = sum(i==j for i,j in zip(secret,guess))        return '%sA%sB' %(bull_count,sum((a&b).values())-bull_count)
原创粉丝点击