Skip to content

Commit 1217e7e

Browse files
committed
Runtime: 46 ms (Top 93.81%) | Memory: 14.7 MB (Top 75.82%)
1 parent 66b7053 commit 1217e7e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
# Runtime: 46 ms (Top 93.81%) | Memory: 14.7 MB (Top 75.82%)
12
# Definition for a binary tree node.
23
# class TreeNode:
3-
# def __init__(self, val=0, left=None, right=None):
4-
# self.val = val
5-
# self.left = left
6-
# self.right = right
4+
# def __init__(self, val=0, left=None, right=None):
5+
# self.val = val
6+
# self.left = left
7+
# self.right = right
78
class Solution:
89
def widthOfBinaryTree(self, root: Optional[TreeNode]) -> int:
910
q = deque([(root, 0)])
1011
res = 0
11-
12+
1213
while q:
1314
res = max(res, q[-1][1] - q[0][1] + 1)
1415
for _ in range(len(q)):
1516
curr, pos = q.popleft()
16-
17+
1718
if curr.left:
1819
q.append((curr.left, pos*2))
1920
if curr.right:
2021
q.append((curr.right, pos*2 + 1))
21-
22-
return res
22+
23+
return res

0 commit comments

Comments
 (0)