leetcode整理 Tree
StudyCoder
这个作者很懒,什么都没留下…
展开
-
110. Balanced Binary Tree
题目:平衡二叉树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 no转载 2016-07-28 11:53:03 · 211 阅读 · 0 评论 -
129. Sum Root to Leaf Numbers
题目:根到叶子节点数字之和Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 12转载 2016-07-30 15:02:51 · 245 阅读 · 0 评论 -
236. Lowest Common Ancestor of a Binary Tree
题目:二叉树的最小共同父节点Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defi转载 2016-07-30 14:26:45 · 306 阅读 · 0 评论 -
235. Lowest Common Ancestor of a Binary Search Tree
题目:二叉搜索树的最小共同父节点Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ance转载 2016-07-28 11:14:52 · 207 阅读 · 0 评论 -
199. Binary Tree Right Side View
题目:二叉树右侧视图Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following bina转载 2016-07-30 11:30:59 · 880 阅读 · 0 评论 -
337. House Robber III
题目:入室盗贼3The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house转载 2016-07-30 11:00:35 · 290 阅读 · 0 评论 -
116. Populating Next Right Pointers in Each Node
题目:填充每个节点的指向右边邻居的指针Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point转载 2016-07-30 10:09:55 · 295 阅读 · 0 评论 -
114. Flatten Binary Tree to Linked List
题目:二叉树展开成链表Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should loo转载 2016-07-29 15:47:37 · 250 阅读 · 0 评论 -
113. Path Sum II
题目:二叉树路径和2Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5转载 2016-07-29 14:52:51 · 243 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
题目:有序数组转为二叉搜索树Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题意:给定一个已经按照递增排序好的数组,将该有序数组转换为一棵高度平衡的二叉搜索树。思路:二叉搜索树的特点是,每个节点都满足左节点代码转载 2016-07-29 11:22:44 · 269 阅读 · 0 评论 -
257. Binary Tree Paths
题目:二叉树路径Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->转载 2016-07-29 10:23:06 · 207 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree
题目:最小树深Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.题意:给定一棵二叉树,找到最小树深转载 2016-07-29 09:49:18 · 217 阅读 · 0 评论 -
112. Path Sum
题目:二叉树路径和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.For example:Given the below binar转载 2016-07-28 16:11:15 · 267 阅读 · 0 评论 -
100. Same Tree
题目:相同树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.转载 2016-07-28 15:43:04 · 194 阅读 · 0 评论 -
107. Binary Tree Level Order Traversal II
题目:二叉树层序遍历2Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3转载 2016-07-28 15:26:32 · 217 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree
题目:二叉树的最大深度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.题意:给定一个二叉树,找到该树转载 2016-07-28 14:55:55 · 207 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
题目:二叉树层序遍历Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7],转载 2016-07-28 14:29:47 · 219 阅读 · 0 评论 -
101. Symmetric Tree
题目:对称树Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \转载 2016-07-28 13:53:24 · 233 阅读 · 0 评论 -
98. Validate Binary Search Tree
题目:验证二叉搜索树Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than t转载 2016-07-29 14:21:37 · 1292 阅读 · 0 评论