标签:obj == str ota solution eth turn count and
class Solution(object):
def getHint(self, secret, guess):
"""
:type secret: str
:type guess: str
:rtype: str
"""
A=sum(a==b for a,b in zip(secret,guess))
total=sum(min(secret.count(i),guess.count(i)) for i in set(guess))
return ‘%sA%sB‘%(A,total-A)
class Solution(object):
def getHint(self, secret, guess):
"""
:type secret: str
:type guess: str
:rtype: str
"""
cnt={}
for i in secret:
if i not in cnt:
cnt[i]=1
else:
cnt[i]+=1
A=0
B=0
not_bulls=[]
for j in range(len(guess)):
if guess[j] == secret[j]:
A+=1
cnt[guess[j]]-=1
else:
not_bulls.append(guess[j])
for j in not_bulls:
if j in cnt and cnt[j]<>0:
B+=1
cnt[j]-=1
return ‘%sA%sB‘%(A,B)
标签:obj == str ota solution eth turn count and
原文地址:https://www.cnblogs.com/ffeng0312/p/9625372.html