Registry Mirror
搜索
Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Files
Expand file tree
master
Breadcrumbs
leetcode
/
algorithms
/
python
/
AddOneRowToTree
/
addOneRow.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
12 lines (10 loc) · 402 Bytes
master
Breadcrumbs
leetcode
/
algorithms
/
python
/
AddOneRowToTree
/
addOneRow.py
Copy path
Top
File metadata and controls
Code
Blame
12 lines (10 loc) · 402 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
# get the nodes at (d - 1) layer:
def addOneRow(self, root, v, d):
dummy, dummy.left = TreeNode(v), root
row = [dummy]
for _ in range(d - 1):
row = [kid for node in row for kid in (node.left, node.right) if kid]
for node in row:
node.left, node.left.left = TreeNode(v), node.left
node.right, node.right.right = TreeNode(v), node.right
return dummy.left
You can’t perform that action at this time.