Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- private:
- void make_order(TreeNode *cur, int level, vector<vector<int>> &ans)
- {
- if (ans.size() == level)
- ans.resize(level + 1);
- ans[level].push_back(cur->val);
- if (cur->left != NULL)
- make_order(cur->left, level + 1, ans);
- if (cur->right != NULL)
- make_order(cur->right, level + 1, ans);
- return;
- }
- public:
- vector<vector<int>> levelOrder(TreeNode* root) {
- vector<vector<int>> ans;
- if (root == NULL)
- return ans;
- make_order(root, 0, ans);
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement