Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.思路分析:这题比较简单,关于树的题目通常都可以用递归解决,这题也不例外,递归解法的思...
分类:
其他好文 时间:
2015-03-19 06:23:34
阅读次数:
126
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.思路分析:判断两个树是否相同,基本也...
分类:
其他好文 时间:
2015-03-19 06:23:30
阅读次数:
95
Similar to the sorted array. But we have to remember, the position of node not depends on the index. So we need do two more things:1. Ensure the point...
分类:
其他好文 时间:
2015-03-19 06:20:30
阅读次数:
132
Only different with preorder and postorder is that the root start from the beginning for preorder. 1 /** 2 * Definition for binary tree 3 * struct T.....
分类:
其他好文 时间:
2015-03-19 06:20:26
阅读次数:
122
It is kind of binary search. Since this is a sorted array, we can treat it as inorder traversal. And we can define the root node for the Tree.So find ...
分类:
其他好文 时间:
2015-03-19 06:19:48
阅读次数:
105
For this problem just need to know the structure of two traversal.1. It is hard to find the root node in the inorder traversal but it is easy in posto...
分类:
其他好文 时间:
2015-03-19 06:19:44
阅读次数:
119
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should return...
分类:
其他好文 时间:
2015-03-18 18:06:47
阅读次数:
92
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Fo...
分类:
其他好文 时间:
2015-03-18 15:20:00
阅读次数:
131
先序遍历:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), ...
分类:
其他好文 时间:
2015-03-18 13:48:17
阅读次数:
124
Made a stupid bug....... When reverse the vector, stop it at mid. Otherwise, it will swap back......Mark!!!!!!!! 1 /** 2 * Definition for binary tree....
分类:
其他好文 时间:
2015-03-18 10:23:29
阅读次数:
120