1class Solution {2public:3vector<vector<string>> res;45int height(TreeNode *root) {6if (!root) return 0;7return 1 + max(height(root->left), height(root->right));8}910void fill(TreeNode *root, int r, int c, int h) {11if (!root) return;12res[r][c] = to_string(root->val);13fill(root->left, r + 1, c - pow(2, h - r - 1), h);14fill(root->right, r + 1, c + pow(2, h - r - 1), h);15}1617vector<vector<string>> printTree(TreeNode *root) {18int h = height(root);19int c = pow(2, h) - 1;20res.resize(h, vector<string>(c, ""));21fill(root, 0, (c - 1) / 2, h - 1);22return res;23}24};