LintCode: Identical Binary Tree】的更多相关文章

Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value. Have you met this question in a real interview?     Example 1 1 / \ / \ 2 2 and 2 2 / / 4 4 are ide…
C++ /** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * this->val = val; * this->left = this->right = NULL; * } * } */ class Solution { public: /** * @aaram a, b, the root of bin…
Binary Tree: 0到2个子节点; Binary Search Tree: 所有左边的子节点 < node自身 < 所有右边的子节点: 1. Full类型: 除最下面一层外, 每一层都有两个子节点: 2. Complete类型: 除最下面一层外为Full类型, 但是最下面一层最所有子节点靠左: 3. Balanced类型: 左右两个子树的长度相差小于等于一: /** * Definition of TreeNode: * public class TreeNode { * public…
Flatten a binary tree to a fake "linked list" in pre-order traversal. Here we use the right pointer in TreeNode as the next pointer in ListNode. Notice Don't forget to mark the left child of each node to null. Or you will get Time Limit Exceeded…
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Example Given binary tree A = {3,9,…
题目: 二叉树的后序遍历 给出一棵二叉树,返回其节点值的后序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [3,2,1] 挑战 你能使用非递归实现么? 解题: 递归程序好简单 Java程序: /** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * th…
题目: 二叉树的前序遍历 给出一棵二叉树,返回其节点值的前序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [1,2,3]. 挑战 你能使用非递归实现么? 解题: 通过递归实现,根节点->左节点->右节点 Java程序: /** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(…
C++ Traverse /** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * this->val = val; * this->left = this->right = NULL; * } * } */ class Solution { public: /** * @param root: a Tree…
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. Example Given 4 points: (1,2), (3,6), (0,0), (1,3). The maximum number is 3. LeeCode上的原题,可参见我之前的博客Invert Binary Tree 翻转二叉树. 解法一: // Recursion class So…
Given a k-ary tree, find the length of the longest consecutive sequence path. The path could be start and end at any node in the tree ExampleAn example of test data: k-ary tree 5<6<7<>,5<>,8<>>,4<3<>,5<>,3<>…