Python simply solution beats 94% submissons


  • 0
    W
    bulls, both = 0, 0
    length = len(guess)
    for i in xrange(length):
        if guess[i] == secret[i]:
            bulls += 1
    for i in set(secret) & set(guess):
        both += min(secret.count(i), guess.count(i))
    return "{bulls}A{cows}B".format(bulls=bulls, cows=both - bulls)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.