【leetcode❤python】299. Bulls and Cows

class Solution(object):
    def getHint(self, secret, guess):
        """
        :type secret: str
        :type guess: str
        :rtype: str
        """
        countA,i,numList=0,-1,[[0,0] for i in range(10)]
        while True:
            i+=1
            try:
                if secret[i]==guess[i]:countA+=1
                else:
                    numList[int(secret[i])][0]+=1
                    numList[int(guess[i])][1]+=1
            except:break

        return "%sA%sB"%(countA,sum(min(i,v) for i,v in numList))

原文地址:https://www.cnblogs.com/kwangeline/p/5993760.html