码迷,mamicode.com
首页 >  
搜索关键字:binary trees    ( 12390个结果)
LeetCode – Refresh – Binary Tree Pre Order Traversal
Same with inorder.1. recursive: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeN...
分类:其他好文   时间:2015-03-18 08:58:05    阅读次数:131
LeetCode – Refresh – Binary Tree Level Order Traversal ii
This question is almost same as the previous one.I just use a stack (another vector) of vector to store the level result. Then reverse it. 1 /** 2 * ....
分类:其他好文   时间:2015-03-18 08:56:41    阅读次数:155
LeetCode – Refresh – Binary Tree Maximum Path Sum
Use lMax get the maximum value of a sub SINGLE branch (left branch or right branch or just current node).Use gMax get the maximum value of the whole s...
分类:其他好文   时间:2015-03-18 08:56:01    阅读次数:190
LeetCode – Refresh – Binary Tree Iterator
It is similar to use stack for BST inorder traversal.So do the same thing :1. Get stack to store right branchs(include current node).2. When you pop t...
分类:其他好文   时间:2015-03-18 07:50:34    阅读次数:139
LeetCode – Refresh – Add Two Numbers
Same with add binary. You can also skip delete the result pointer. But just return result->next. Depends on the interviewer. 1 /** 2 * Definition for....
分类:其他好文   时间:2015-03-18 07:47:51    阅读次数:114
LeetCode – Refresh – Balanced Binary Tree
Need a helper function to return the binary tree maximum height. If the return value is -1, it means there is a imbalanced subbranch . 1 /** 2 * Defi....
分类:其他好文   时间:2015-03-18 07:47:44    阅读次数:123
LeetCode – Refresh – Binary Tree Inorder Traversal
There are three methods to do it:1. recursive(use memory stack): (Time O(n), Space O(logn) 1 /** 2 * Definition for binary tree 3 * struct TreeNode .....
分类:其他好文   时间:2015-03-18 07:46:37    阅读次数:117
[LeetCode] Binary Tree Inorder Traversal 中序排序
Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note...
分类:编程语言   时间:2015-03-18 01:04:11    阅读次数:209
【LeetCode】 Sum Root to Leaf Numbers
第一次写的解法,。对于只有一个儿子的节点重复了两次 。。结果就弄复杂了。。我也觉得不应该能有这么多的重复嘛 /** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) ...
分类:其他好文   时间:2015-03-17 22:00:13    阅读次数:130
【LeetCode】 Populating Next Right Pointers in Each Node 完全二叉树
题目:Populating Next Right Pointers in Each Node /* * LeetCode Populating Next Right Pointers in Each Node * 题目:为树的每个节点增加一个next指针,指向树状结构排列时自己的右边节点,如果右边没有节点则置为null * * Definition for binary tree wit...
分类:其他好文   时间:2015-03-17 21:54:58    阅读次数:107
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!