leetcode:299. 猜数字游戏(哈希表)
程序员文章站
2022-04-24 12:53:28
...
题目:
python代码:
class Solution:
def getHint(self, secret: str, guess: str) -> str:
c1=0
A1=[0 for x in range(0,10)]
A2=[0 for x in range(0,10)]
for x in range(0,len(guess)):
if secret[x]==guess[x]:
c1=c1+1
else :
A1[int(secret[x])]+=1
A2[int(guess[x])]+=1
c2=0
for x in range(0,10):
c2+=min(A1[x],A2[x])
return ''+str(c1)+'A'+str(c2)+'B'
python收获:
A1=[0 for x in range(0,10)]
这种创建列表的方式要学会啊