-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBulbSwitcherII(dfs).py
42 lines (35 loc) · 1.11 KB
/
BulbSwitcherII(dfs).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
class Solution:
def flipLights(self, n: int, m: int) -> int:
'''
dfs - tle
'''
def t1(status):
for i in range(len(status)):
status[i] = not status[i]
return status
def t2(status):
for i in range(1,len(status),2):
status[i] = not status[i]
return status
def t3(status):
for i in range(0,len(status),2):
status[i] = not status[i]
return status
def t4(status):
for i in range(len(status)):
if (i)%3 == 0:
status[i] = not status[i]
return status
s = []
def dfs(status, index):
if index == m:
if status not in s:
s.append(status)
return
dfs(t1(status[:]),index+1)
dfs(t2(status[:]),index+1)
dfs(t3(status[:]),index+1)
dfs(t4(status[:]),index+1)
return
dfs([True]*n,0)
return len(s)