Created
September 29, 2019 03:22
-
-
Save atul-chaudhary/9522546a8aca91405473ddacfb4359ac to your computer and use it in GitHub Desktop.
leetcode: problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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