给你一棵二叉树的根节点 root
,请你构造一个下标从 0 开始、大小为 m x n
的字符串矩阵 res
,用以表示树的 格式化布局 。构造此格式化布局矩阵需要遵循以下规则:
height
,矩阵的行数 m
应该等于 height + 1
。n
应该等于 2height+1 - 1
。res[0][(n-1)/2]
。res[r][c]
,将其左子节点放置在 res[r+1][c-2height-r-1]
,右子节点放置在 res[r+1][c+2height-r-1]
。""
。返回构造得到的矩阵 res
。
示例 1:
输入:root = [1,2] 输出: [["","1",""], ["2","",""]]
示例 2:
输入:root = [1,2,3,null,4] 输出: [["","","","1","","",""], ["","2","","","","3",""], ["","","4","","","",""]]
提示:
[1, 210]
内-99 <= Node.val <= 99
[1, 10]
内