【LeetCode】树(共94题)

【94】Binary Tree Inorder Traversal 

【95】Unique Binary Search Trees II 

【96】Unique Binary Search Trees 

【98】Validate Binary Search Tree 

写个函数检查一棵树是不是BST

题解:直接判断左儿子比根小,右儿子比跟大是会WA的... 举个会WA的例子。

 

View Code

 【99】Recover Binary Search Tree 

【100】Same Tree

【101】Symmetric Tree 

扫描二维码关注公众号,回复: 3840942 查看本文章

【102】Binary Tree Level Order Traversal 

【103】Binary Tree Zigzag Level Order Traversal 

【104】Maximum Depth of Binary Tree 

【105】Construct Binary Tree from Preorder and Inorder Traversal 

【106】Construct Binary Tree from Inorder and Postorder Traversal 

给中序遍历 和 后序遍历, 重建二叉树。

没啥难度,一次ac

View Code

 

【107】Binary Tree Level Order Traversal II

【108】Convert Sorted Array to Binary Search Tree 

给一个增序的vector, 建立一棵高度平衡的BST.

这个题一开始懵了,不会做。。。信不信考到你就挂了orz

思路是二分的思想,从root开始建树,然后左儿子,右儿子。

View Code

 

【110】Balanced Binary Tree 

【111】Minimum Depth of Binary Tree 

【112】Path Sum 

【113】Path Sum II 

【114】Flatten Binary Tree to Linked List 

把一颗二叉树拍平成一个链表。如图。判空,莫忘。要取一个节点的子节点之前,要判断这个节点是否为空。

View Code

 

【116】Populating Next Right Pointers in Each Node 

【117】Populating Next Right Pointers in Each Node II 

【124】Binary Tree Maximum Path Sum 

【129】Sum Root to Leaf Numbers 

【144】Binary Tree Preorder Traversal 

【145】Binary Tree Postorder Traversal 

【156】Binary Tree Upside Down 

【173】Binary Search Tree Iterator 

【199】Binary Tree Right Side View 

【222】Count Complete Tree Nodes 

【226】Invert Binary Tree 

【230】Kth Smallest Element in a BST 

【235】Lowest Common Ancestor of a Binary Search Tree 

【236】Lowest Common Ancestor of a Binary Tree 

【250】Count Univalue Subtrees 

【255】Verify Preorder Sequence in Binary Search Tree 

【257】Binary Tree Paths 

【270】Closest Binary Search Tree Value 

【272】Closest Binary Search Tree Value II 

【285】Inorder Successor in BST 

【297】Serialize and Deserialize Binary Tree 

【298】Binary Tree Longest Consecutive Sequence 

【333】Largest BST Subtree 

【337】House Robber III 

【366】Find Leaves of Binary Tree 

【404】Sum of Left Leaves 

【426】Convert Binary Search Tree to Sorted Doubly Linked List 

【428】Serialize and Deserialize N-ary Tree 

【429】N-ary Tree Level Order Traversal 

【431】Encode N-ary Tree to Binary Tree 

【437】Path Sum III 

【449】Serialize and Deserialize BST 

【450】Delete Node in a BST 

【501】Find Mode in Binary Search Tree 

【508】Most Frequent Subtree Sum 

【513】Find Bottom Left Tree Value 

【515】Find Largest Value in Each Tree Row 

【536】Construct Binary Tree from String 

【538】Convert BST to Greater Tree 

【543】Diameter of Binary Tree 

【545】Boundary of Binary Tree 

【549】Binary Tree Longest Consecutive Sequence II 

【559】Maximum Depth of N-ary Tree 

【563】Binary Tree Tilt 

【572】Subtree of Another Tree 

【582】Kill Process 

【589】N-ary Tree Preorder Traversal 

【590】N-ary Tree Postorder Traversal 

【606】Construct String from Binary Tree 

【617】Merge Two Binary Trees 

【623】Add One Row to Tree 

【637】Average of Levels in Binary Tree 

【652】Find Duplicate Subtrees 

【653】Two Sum IV - Input is a BST 

【654】Maximum Binary Tree 

【655】Print Binary Tree 

【662】Maximum Width of Binary Tree 

【663】Equal Tree Partition 

【666】Path Sum IV 

【669】Trim a Binary Search Tree 

【671】Second Minimum Node In a Binary Tree 

【684】Redundant Connection 

【685】Redundant Connection II 

【687】Longest Univalue Path 

【700】Search in a Binary Search Tree 

【701】Insert into a Binary Search Tree 

【742】Closest Leaf in a Binary Tree 

【814】Binary Tree Pruning 

【834】Sum of Distances in Tree 

【863】All Nodes Distance K in Binary Tree 

【865】Smallest Subtree with all the Deepest Nodes 

【872】Leaf-Similar Trees 

【889】Construct Binary Tree from Preorder and Postorder Traversal 

【894】All Possible Full Binary Trees 

【897】Increasing Order Search Tree 

猜你喜欢

转载自www.cnblogs.com/zhangwanying/p/6753328.html