Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 481bd29

Browse files
Update README_EN.md
1 parent f1fe6d9 commit 481bd29

File tree

1 file changed

+25
-25
lines changed
  • solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony

1 file changed

+25
-25
lines changed

‎solution/1900-1999/1916.Count Ways to Build Rooms in an Ant Colony/README_EN.md‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,31 @@ tags:
105105

106106
```python
107107
class Solution:
108-
def waysToBuildRooms(self, prevRoom: List[int]) -> int:
109-
modulo = 10**9 + 7
110-
ingoing = defaultdict(set)
111-
outgoing = defaultdict(set)
112-
113-
for i in range(1, len(prevRoom)):
114-
ingoing[i].add(prevRoom[i])
115-
outgoing[prevRoom[i]].add(i)
116-
ans = [1]
117-
118-
def recurse(i):
119-
if len(outgoing[i]) == 0:
120-
return1# just self
121-
122-
nodes_in_tree = 0
123-
for v in outgoing[i]:
124-
cn = recurse(v)
125-
if nodes_in_tree != 0:
126-
ans[0] *= comb(nodes_in_tree + cn, cn)
127-
ans[0] %= modulo
128-
nodes_in_tree += cn
129-
return nodes_in_tree + 1
130-
131-
recurse(0)
132-
return ans[0] % modulo
108+
def waysToBuildRooms(self, prevRoom: List[int]) -> int:
109+
modulo = 10**9 + 7
110+
ingoing = defaultdict(set)
111+
outgoing = defaultdict(set)
112+
113+
for i in range(1, len(prevRoom)):
114+
ingoing[i].add(prevRoom[i])
115+
outgoing[prevRoom[i]].add(i)
116+
ans = [1]
117+
118+
def recurse(i):
119+
if len(outgoing[i]) == 0:
120+
return1
121+
122+
nodes_in_tree = 0
123+
for v in outgoing[i]:
124+
cn = recurse(v)
125+
if nodes_in_tree != 0:
126+
ans[0] *= comb(nodes_in_tree + cn, cn)
127+
ans[0] %= modulo
128+
nodes_in_tree += cn
129+
return nodes_in_tree + 1
130+
131+
recurse(0)
132+
return ans[0] % modulo
133133
```
134134

135135
#### Java

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /