Share a straightforward passing python code


  • 0
    K
    class Solution(object):
        def getHint(self, secret, guess):
            self.a=0
            self.b=0
            tmplst=list(secret)
            tmpgs=list(guess)
            for i in range(len(tmplst)):
                if tmpgs[i]==tmplst[i]:
                    self.a+=1
                    tmplst[i]='x'
                    tmpgs[i]='y'
            for i in range(len(tmplst)):
                try:
                    index=tmplst.index(tmpgs[i])
                    self.b+=1
                    tmplst[index]='x'
                except:
                    continue
                    
            return str(self.a)+'A'+str(self.b)+'B'

Log in to reply
 

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