Skip to content

Commit e0f2fb2

Browse files
Create bulls_and_cows.py
1 parent 2a81a24 commit e0f2fb2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bulls_and_cows.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def getHint(self, secret: str, guess: str) -> str:
3+
d = {}
4+
bull, cow = 0,0
5+
6+
for index,s in enumerate(secret):
7+
if guess[index] == s:
8+
bull += 1
9+
else:
10+
d[s] = d.get(s,0) + 1
11+
12+
for index,s in enumerate(secret):
13+
if (guess[index] != s) & (d.get(guess[index],0) != 0):
14+
cow += 1
15+
d[guess[index]] -= 1
16+
17+
return str(bull) + "A" + str(cow) + "B"

0 commit comments

Comments
 (0)