yuliji
10/14/2014 - 1:01 PM

binary tree post order traveral

binary tree post order traveral

class Solution {
public:
    vector<int> postorderTraversal(TreeNode *root) {
        vector<int> result;
        
        if(root == NULL){
            return result;
        }
        
        vector<int> leftChild = postorderTraversal(root->left);
        vector<int> rightChild = postorderTraversal(root->right);
        int i;
        for(i = 0; i < leftChild.size(); i++){
            result.push_back(leftChild[i]);
        }
        for(i = 0; i < rightChild.size(); i++){
            result.push_back(rightChild[i]);
        }
        result.push_back(root->val);
        return result;
        
    }
};