![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构-Tree
文章平均质量分 65
Alice熹爱学习
做个终身学习者,持续迭代;公众号-极客X养成计划;简书-不会停的蜗牛
展开
-
【LEETCODE】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 binary tree, 1原创 2015-11-05 21:27:14 · 752 阅读 · 0 评论 -
【LEETCODE】100-Same Tree
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原创 2015-10-31 17:53:47 · 711 阅读 · 0 评论 -
【LEETCODE】105-Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. # Definition for a binary tree node. # class TreeNode(o原创 2015-11-11 14:07:49 · 586 阅读 · 0 评论 -
【LEETCODE】106-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. 参考: https://github.com/kamyu104/LeetCode/blob/master/原创 2015-11-10 11:01:39 · 559 阅读 · 0 评论 -
【LEETCODE】173-Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST. Note: next() and原创 2015-11-05 14:48:17 · 904 阅读 · 0 评论 -
【LEETCODE】94-Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.原创 2015-11-03 19:00:31 · 473 阅读 · 0 评论 -
【LEETCODE】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,#,#,15,7}, 3 / \ 9 20 /原创 2015-11-02 16:51:57 · 506 阅读 · 0 评论 -
【LEETCODE】104-Maximum Depth of Binary Tree
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.原创 2015-10-31 10:56:04 · 1147 阅读 · 0 评论 -
【LEETCODE】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 defined between two nodes原创 2015-11-10 17:09:33 · 443 阅读 · 0 评论 -
【LEETCODE】96-Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2015-11-03 22:07:33 · 499 阅读 · 0 评论 -
【LEETCODE】226-Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 # Definition for a binary tree node. # class TreeNode原创 2015-10-31 18:43:32 · 778 阅读 · 0 评论 -
【LEETCODE】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. # Definition for a binary tree nod原创 2015-10-31 19:56:41 · 596 阅读 · 0 评论 -
【LEETCODE】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 ancestor is defined betwee原创 2015-10-31 20:40:04 · 522 阅读 · 0 评论 -
【LEETCODE】95-Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's shown below. 1 3原创 2015-11-04 10:28:34 · 431 阅读 · 0 评论 -
【LEETCODE】145-Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. Note: Recursive solution i原创 2015-11-03 11:30:33 · 437 阅读 · 0 评论 -
【LEETCODE】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. # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): #原创 2015-11-04 20:17:48 · 544 阅读 · 0 评论 -
【LEETCODE】107-Binary Tree Level Order Traversal II
Given 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,9,20,#,#,15,7},原创 2015-11-02 19:23:09 · 529 阅读 · 0 评论 -
【LEETCODE】109-Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. # Definition for singly-linked list. # class ListNode(object): # def __init__(sel原创 2015-11-09 17:16:00 · 630 阅读 · 0 评论 -
【LEETCODE】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 6 The flattened tree should look like: 1原创 2015-11-06 19:16:09 · 635 阅读 · 0 评论 -
【LEETCODE】257-Binary Tree Paths
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5", "1->3"] # Defi原创 2015-11-01 20:16:30 · 632 阅读 · 0 评论 -
【LEETCODE】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 is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the fo原创 2015-11-01 16:29:42 · 589 阅读 · 0 评论 -
【LEETCODE】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 node never differ原创 2015-11-01 11:55:27 · 622 阅读 · 0 评论 -
【LEETCODE】144-Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]. 参考: http://bookshadow.原创 2015-11-03 16:32:40 · 542 阅读 · 0 评论