#BINARY

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

543. Diameter of Binary Tree

Givenabinarytree,youneedtocomputethelengthofthediameterofthetree.Thediameterofabinarytreeisthelengthofthelongestpathbetweenanytwonodesinatree.Thispathmayormayno...

自己实现数据结构系列五---BinarySearchTree

一.二分搜索树:1.代码:publicclassBST<EextendsComparable<E>>{privateclassNode{publicEe;publicNodeleft;publicNoderight;publicNode(Ee){this.e=e;left=null;right=...

二叉树BinaryTree构建测试(无序)

  此测试仅用于二叉树基本的性质测试,不包含插入、删除测试(此类一般属于有序树基本操作)。//二叉树树类publicclassBinaryTree{publicTreeNoderoot;//有一个根节点publicstaticintindex;publicTreeNodeCreateBTree(int[]a){Tree...

leetcode 654. Maximum Binary Tree

Givenanintegerarraywithnoduplicates.Amaximumtreebuildingonthisarrayisdefinedasfollow:Therootisthemaximumnumberinthearray.Theleftsubtreeisthemaximumtreeconstruct...

convert decimal to binary

 publicclassSolution{publicstaticvoidmain(String[]args){intdNum=1264;Stringstr="";while(dNum>0){intrem=dNum%2;str=rem+str;dNum=dNum/2;}System.out.printl...
代码星球 ·2020-11-02

convert decimal to binary using inbuilt function

 packagetestpacknm;importjava.util.Scanner;publicclasstestcnm{publicstaticvoidmain(String[]args){intdNum=5;System.out.println("Binaryis:"+Integer.toBinaryS...

650. Find Leaves of Binary Tree

  classSolution{public:vector<vector<int>>findLeaves(TreeNode*root){vector<vector<int>>res;while(root){vector<int>leaves...
代码星球 ·2020-10-13
首页上一页12345...下一页尾页