Skip to content

Instantly share code, notes, and snippets.

@atul-chaudhary
Created September 29, 2019 03:22
Show Gist options
  • Save atul-chaudhary/9522546a8aca91405473ddacfb4359ac to your computer and use it in GitHub Desktop.
Save atul-chaudhary/9522546a8aca91405473ddacfb4359ac to your computer and use it in GitHub Desktop.
leetcode: problem
class Solution:
def getHint(self, secret: str, guess: str) -> str:
d = {}
bull = 0
cow = 0
for i in range(len(secret)):
if (secret[i] == guess[i]):
bull += 1
else:
if (secret[i] in d):
d[secret[i]] += 1
else:
d[secret[i]] = 1
for i in range(len(guess)):
if (secret[i] != guess[i]):
if (d[guess[i]]):
d[guess[i]] -= 1
cow += 1
if (d[guess[i]] == 0):
del d[guess[i]]
st = str(bull) + 'A' + str(cow) + 'B'
return st
S = Solution()
print(S.getHint('1807', '7810'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment