-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem299.py
More file actions
32 lines (30 loc) · 741 Bytes
/
problem299.py
File metadata and controls
32 lines (30 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'''
Easy Solution.
'''
class Solution(object):
def getHint(self, secret, guess):
"""
:type secret: str
:type guess: str
:rtype: str
"""
import collections
cnt_secret = collections.Counter(secret)
cnt_guess = collections.Counter(guess)
Bulls,Cows = 0,0
for i in range(len(secret)):
if secret[i] == guess[i]:
Bulls += 1
cnt_secret[secret[i]] -= 1
cnt_guess[guess[i]] -= 1
for i in range(len(secret)):
if guess[i] in secret and cnt_guess[guess[i]] != 0 and cnt_secret[guess[i]] != 0:
Cows += 1
cnt_secret[guess[i]] -= 1
cnt_guess[guess[i]] -= 1
return str(Bulls)+'A'+str(Cows)+'B'
if __name__ == '__main__':
s = Solution()
secret = '1122'
guess = '1222'
print s.getHint(secret,guess)