Advertisement
tanchukw

Untitled

Sep 14th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. class Solution {
  2. private:
  3.     void make_order(TreeNode *cur, int level, vector<vector<int>> &ans)
  4.     {
  5.         if (ans.size() == level)
  6.             ans.resize(level + 1);
  7.         ans[level].push_back(cur->val);
  8.         if (cur->left != NULL)
  9.             make_order(cur->left, level + 1, ans);
  10.         if (cur->right != NULL)
  11.             make_order(cur->right, level + 1, ans);
  12.         return;
  13.     }
  14. public:
  15.     vector<vector<int>> levelOrder(TreeNode* root) {
  16.         vector<vector<int>> ans;
  17.         if (root == NULL)
  18.             return ans;
  19.         make_order(root, 0, ans);
  20.         return ans;
  21.     }
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement