【leetcode】Binary Tree Postorder Traversal
2014-06-11 10:18
288 查看
Given a binary tree, return the postorder traversal of its nodes' values.
For example:
Given binary tree
return
题解:用了平凡的递归方法:
For example:
Given binary tree
{1,#,2,3},
1 \ 2 / 3
return
[3,2,1].
题解:用了平凡的递归方法:
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: vector<int> postorderTraversal(TreeNode *root) { vector<int> answer; post(root,answer); return answer; } void post(TreeNode* root,vector<int>& nodes){ if(root == NULL) return; post(root->left,nodes); post(root->right,nodes); nodes.push_back(root->val); return; } };
相关文章推荐
- Binary Tree Postorder Traversal --leetcode
- [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal
- leetcode--Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode——106. Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode] Binary Tree Preorder/Inorder/Postorder Traversal
- LeetCode-Binary Tree Postorder Traversal
- Construct Binary Tree from Inorder and Postorder Traversal (leetcode)
- leetcode - Binary Tree Preorder Traversal && Binary Tree Inorder Traversal && Binary Tree Postorder Traversal
- leetcode——106——Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode | Binary Tree Postorder Traversal
- LeetCode "Construct Binary Tree from Inorder and Postorder Traversal"
- [leetcode]Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode: Construct Binary Tree from Inorder and Postorder Traversal
- [leetcode]Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode] Binary Tree Postorder Traversal [42]
- LEETCODE: Binary Tree Postorder Traversal
- LeetCode 105, 106. Construct Binary Tree from Preorder and Inorder/Inorder and Postorder Traversal
- leetcode第一刷_Construct Binary Tree from Inorder and Postorder Traversal
- leetcode106~Construct Binary Tree from Inorder and Postorder Traversal
- Leetcode Binary Tree Postorder Traversal