Python Solution


  • -1
    C
    class Solution(object):
        def getHint(self, secret, guess):
            a=len(secret)
            i=0
            bull=0
            cow=0
            while i<a:
                if guess[i]==secret[i]:
                    bull+=1
                i+=1
            for j in set(guess):
                if j in set(secret):
                    cow+=min(guess.count(j),secret.count(j))
            cow-=bull
            return str(bull)+"A"+str(cow)+"B"
    

  • 0
    P

    The complexity of your code isn't great.

    O(len(secret) + len(guess)^2)


  • 0
    C

    @pisskidney I think O(len(secret)*len(guess)). Do you have any thought about reducing it to O(n)?


Log in to reply
 

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