python3


  • 0
    Q

    I use Python3 to solve the problem.


  • 0
    Q

    class Solution:
    def getHint(self, secret, guess):
    """
    :type secret: str
    :type guess: str
    :rtype: str
    """
    secret1=set(secret)
    secret2=list(secret1)
    P='0123456789'
    print(secret1)
    g={}
    m=0
    for i in secret2:
    g[i]=0
    for i in list(secret):
    w1=P.find(i)
    g[i]=g[i]+1
    print(g)
    guess1=set(guess)
    guess2=list(guess1)
    print(guess1)
    G={}
    M=0
    for i in guess2:
    G[i]=0
    for i in list(guess):
    w1=P.find(i)
    G[i]=G[i]+1
    print(g)
    f=0
    F=0
    for i in G:
    if i in g:
    f=f+min(g[i],G[i])
    for i in range(len(list(secret))):
    if list(secret)[i]==list(guess)[i]:
    f=f-1
    F=F+1
    W='%sA%sB'%(F,f)
    return(W)


Log in to reply
 

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