Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).
    For example:
    Given binary tree [3,9,20,null,null,15,7],
    3
    / \
    9 20
    / \
    15 7
    return its bottom-up level order traversal as:
    [
    [15,7],
    [9,20],
    [3]
    ]

    Runtime: 8 ms, faster than 100.00% of C++ online submissions for Binary Tree Level Order Traversal II.
    Memory Usage: 15 MB, less than 13.70% of C++ online submissions for Binary Tree Level Order Traversal II.

    1. /**
    2. * Definition for a binary tree node.
    3. * struct TreeNode {
    4. * int val;
    5. * TreeNode *left;
    6. * TreeNode *right;
    7. * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
    8. * };
    9. */
    10. class Solution {
    11. public:
    12. vector<vector<int>> levelOrderBottom(TreeNode* root) {
    13. vector<vector<int>> result;
    14. // tips: regard level of depth as index.
    15. traverse(root, result, 0);
    16. // reverse
    17. reverse(result.begin(), result.end());
    18. return result;
    19. }
    20. void traverse(TreeNode* root, vector<vector<int>> &v, int level) {
    21. if (root == NULL) {
    22. return;
    23. }
    24. if (v.empty() || level > (v.size() - 1)) { // add a vector for current level if it doesn't exist.
    25. v.push_back(vector<int>());
    26. }
    27. // push_back to the vector for current level;
    28. v[level].push_back(root->val);
    29. int nextLevel = level + 1;
    30. traverse(root->left, v, nextLevel);
    31. traverse(root->right, v, nextLevel);
    32. }
    33. };