int widths(n): if n == null: return 0 width = {left = 0, right= 0} widths(n, 0, width) return -width.left + 1 + width.right widths(n, offset, width): if n == null: return width.left = min(width.left, offset) width.right = max(width.right, offset) (n.left, offset -1, width) (n.right, offset +1, width)
No comments:
Post a Comment