Skip to content

Commit efb49e8

Browse files
committed
756
1 parent eed3619 commit efb49e8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

DFS/traditionalDFS/756.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Pyramid Transition Matrix
2+
3+
#### Description
4+
5+
[link](https://leetcode.com/problems/pyramid-transition-matrix/)
6+
7+
---
8+
9+
#### Solution
10+
11+
- See Code
12+
13+
---
14+
15+
#### Code
16+
17+
> 最坏情况:O(n^2)
18+
19+
```python
20+
class Solution:
21+
def pyramidTransition(self, bottom: str, allowed: List[str]) -> bool:
22+
pool=defaultdict(list)
23+
for x in allowed: pool[x[:2]].append(x[2])
24+
25+
def dfs(bottom):
26+
if len(bottom)==1: return True
27+
for b in product(*(pool[x+y] for x,y in zip(bottom[:-1],bottom[1:]))):
28+
if dfs(b): return True
29+
return False
30+
31+
return dfs(bottom)
32+
```

0 commit comments

Comments
 (0)