Solution
-
cowis related with the number of correct characters. Ifbullhas used up the corrected characters, a misplaced correct character is not considered ascow. -
Count the number of
bull. -
Count the sum of matched correct characters.
-
cow = matched - bulldef getHint(self, secret, guess): """ :type secret: str :type guess: str :rtype: str """ bull, cow = 0, 0 dic = collections.Counter(secret) for x, y in zip(secret, guess): if x == y: bull += 1 cow = sum((dic & collections.Counter(guess)).values()) - bull return '{}A{}B'.format(bull, cow)
PREVIOUSPartition Labels
NEXTEdit Distance