File tree 1 file changed +20
-2
lines changed
1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 1
- # Time: O(n^2 )
1
+ # Time: O(n)
2
2
# Space: O(n)
3
3
4
4
import collections
5
5
import itertools
6
6
7
7
8
8
class Solution (object ):
9
+ def findSecretWord (self , wordlist , master ):
10
+ """
11
+ :type wordlist: List[Str]
12
+ :type master: Master
13
+ :rtype: None
14
+ """
15
+ possible = range (len (wordlist ))
16
+ n = 0
17
+ while n < 6 :
18
+ count = [collections .Counter (w [i ] for w in wordlist ) for i in xrange (6 )]
19
+ guess = max (possible , key = lambda x : sum (count [i ][c ] for i , c in enumerate (wordlist [x ])))
20
+ n = master .guess (wordlist [guess ])
21
+ possible = [j for j in possible if sum (a == b for a , b in itertools .izip (wordlist [guess ], wordlist [j ])) == n ]
22
+
23
+
24
+ # Time: O(n^2)
25
+ # Space: O(n)
26
+ class Solution2 (object ):
9
27
def findSecretWord (self , wordlist , master ):
10
28
"""
11
29
:type wordlist: List[Str]
@@ -37,7 +55,7 @@ def solve(H, possible):
37
55
38
56
# Time: O(n^2)
39
57
# Space: O(n)
40
- class Solution2 (object ):
58
+ class Solution3 (object ):
41
59
def findSecretWord (self , wordlist , master ):
42
60
"""
43
61
:type wordlist: List[Str]
You can’t perform that action at this time.
0 commit comments