Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3 ...
原題地址:http: oj.leetcode.com problems binary tree postorder traversal 題意:實現后序遍歷。遞歸實現比較簡單,非遞歸實現。 解題思路:這道題的迭代求解比先序遍歷和后序遍歷要麻煩一些。假設一棵樹是這樣的: 使用一個棧。分幾個步驟: 一,將根節點入棧,並將根節點的孩子入棧,入棧順序為:先入右孩子,再入左孩子,順序不能錯。因為這樣在彈棧時的 ...
2014-05-10 18:40 0 2827 推薦指數:
Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3 ...
原題地址:http://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 題意:根據二叉樹的中序遍歷和后序遍歷恢復二叉樹。 解題思路:看到樹首先想到要用遞歸來解題。以這道題為 ...
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. 遞歸構造 ...
原題地址:http://oj.leetcode.com/problems/binary-tree-inorder-traversal/ 題意:二叉樹的中序遍歷。這道題用遞歸比較簡單,考察的是非遞歸實現二叉樹中序遍歷。中序遍歷順序為:左子樹,根,右子樹。如此遞歸下去。 解題思路:假設樹為: 1 / \ ...
原題地址:http://oj.leetcode.com/problems/binary-tree-preorder-traversal/ 題意:這題用遞歸比較簡單。應該考察的是使用非遞歸實現二叉樹的先序遍歷。先序遍歷的遍歷順序是:根,左子樹,右子樹。 解題思路:如果樹為下圖: 1 / \ ...
原題地址:http://oj.leetcode.com/problems/binary-tree-level-order-traversal/ 題意:二叉樹的層序遍歷的實現。 解題思路:二叉樹的層序遍歷可以用bfs或者dfs來實現。這里使用的dfs實現,代碼比較簡潔。實際上,二叉樹的先序遍歷 ...
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree ...
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, return [3,2,1]. Note ...