#TREE

104. Maximum Depth of Binary Tree

104.MaximumDepthofBinaryTreeEasyGivenabinarytree,finditsmaximumdepth.Themaximumdepthisthenumberofnodesalongthelongestpathfromtherootnodedowntothefarthestleafnod...

102. Binary Tree Level Order Traversal 广度优先遍历

Givenabinarytree,returnthelevelordertraversalofitsnodes'values.(ie,fromlefttoright,levelbylevel).Forexample:Givenbinarytree[3,9,20,null,null,15,7],3/920/157&nbs...

BFS广度优先 vs DFS深度优先 for Binary Tree

https://www.geeksforgeeks.org/bfs-vs-dfs-binary-tree/WhatareBFSandDFSforBinaryTree?ATreeistypicallytraversedintwoways:BreadthFirstTraversal(OrLevelOrderTraversa...
代码星球 ·2021-02-08

108. Convert Sorted Array to Binary Search Tree

https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/Givenanarraywhereelementsaresortedinascendingorder,convertittoaheightbalancedBST.Forthi...

111. Minimum Depth of Binary Tree

Givenabinarytree,finditsminimumdepth.Theminimumdepthisthenumberofnodesalongtheshortestpathfromtherootnodedowntothenearestleafnode.Note: Aleafisanodewithnoc...

110. Balanced Binary Tree

Givenabinarytree,determineifitisheight-balanced.Forthisproblem,aheight-balancedbinarytreeisdefinedas:/abinarytreeinwhichthedepthofthetwosubtreesofeverynodenever...
代码星球 ·2021-02-08

BinaryTree

 publicclassTreeNode{publicintval;publicTreeNodeleft;publicTreeNoderight;publicTreeNode(intx){val=x;}}打印代码privatevoidWriteTreeNode(TreeNodenode){StringBuil...
代码星球 ·2021-02-08

226. Invert Binary Tree

Invertabinarytree.Example:Input:4/27//1369Output:4/72//9631Trivia:ThisproblemwasinspiredbythisoriginaltweetbyMaxHowell:/Google:90%ofourengineersusethesoftwareyo...
代码星球 ·2021-02-08

235. Lowest Common Ancestor of a Binary Search Tree

Givenabinarysearchtree(BST),findthelowestcommonancestor(LCA)oftwogivennodesintheBST.AccordingtothedefinitionofLCAonWikipedia:“Thelowestcommonancestorisdef...

257. Binary Tree Paths

Givenabinarytree,returnallroot-to-leafpaths.Note: Aleafisanodewithnochildren.Example:Input:1/235Output:["1->2->5","1->3"]Explanation:Allroot-to-le...
代码星球 ·2021-02-08

501. Find Mode in Binary Search Tree

Givenabinarysearchtree(BST)withduplicates,findallthe mode(s) (themostfrequentlyoccurredelement)inthegivenBST.AssumeaBSTisdefinedasfollows:Theleftsubtr...
代码星球 ·2021-02-08

538. Convert BST to Greater Tree

GivenaBinarySearchTree(BST),convertittoaGreaterTreesuchthateverykeyoftheoriginalBSTischangedtotheoriginalkeyplussumofallkeysgreaterthantheoriginalkeyinBST.Examp...
代码星球 ·2021-02-08

543. Diameter of Binary Tree

Givenabinarytree,youneedtocomputethelengthofthediameterofthetree.Thediameterofabinarytreeisthelengthofthelongestpathbetweenanytwonodesinatree.Thispathmayormayno...

HashSet非常的消耗空间,TreeSet因为有排序功能,因此资源消耗非常的高,我们应该尽量少使用

注:HashMap底层也是用数组,HashSet底层实际上也是HashMap,HashSet类中有HashMap属性(我们如何在API中查属性)。HashSet实际上为(key.null)类型的HashMap。有key值而没有value值。 正因为以上的原因,TreeSet和TreeMap的实现也有些类似的关...
首页上一页...45678...下一页尾页