from collections import Counter
class Solution:
def getHint(self, s: str, g: str) -> str:
a, b = 0, 0
cs, cg = Counter(), Counter()
for i in range(len(s)):
if s[i] == g[i]:
a += 1
continue
if cg[s[i]]:
cg[s[i]] -= 1
b += 1
else:
cs[s[i]] += 1
if cs[g[i]]:
cs[g[i]] -= 1
b += 1
else:
cg[g[i]] += 1
return f'{a}A{b}B'
299. Bulls and Cows - LeetCode
ยท One min read