【leetcode❤python】 299. Bulls and Cows

#-*- coding: UTF-8 -*-
class Solution(object):  
    def getHint(self, secret, guess):  
        """
        :type secret: str
        :type guess: str
        :rtype: str
        """  
        countA,i,numList=0,-1,[[0,0] for j in range(10)]  
        print numList
        while 1:  
            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))

posted @ 2016-11-13 19:08  火金队长  阅读(261)  评论(0编辑  收藏  举报