-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
299.py
45 lines (38 loc) · 1.45 KB
/
299.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
__________________________________________________________________________________________________
sample 32 ms submission
class Solution:
#import operator
def getHint(self, secret: str, guess: str) -> str:
from collections import Counter
bull = sum(map(operator.eq, secret, guess))
a = Counter(secret)
b = Counter(guess)
cow = sum((a&b).values()) - bull
return '{}A{}B'.format(bull,cow)
__________________________________________________________________________________________________
sample 12980 kb submission
class Solution:
def getHint(self, secret: str, guess: str) -> str:
bulls = 0
w = []
actual = []
l = min(len(secret),len(guess))
for i in range(l):
if secret[i] == guess[i]:
bulls += 1
else:
w.append(guess[i])
actual.append(secret[i])
if len(guess) > l:
for i in range(l,len(guess)):
w.append(guess[i])
if len(secret) > l:
for i in range(l,len(secret)):
actual.append(secret[i])
cows = 0
for x in w:
if x in actual:
cows += 1
actual.remove(x)
return "{bulls}A{cows}B".format(bulls=bulls,cows=cows)
__________________________________________________________________________________________________