此测试仅用于二叉树基本的性质测试,不包含插入.删除测试(此类一般属于有序树基本操作). //二叉树树类 public class BinaryTree { public TreeNode root; //有一个根节点 public static int index; public TreeNode CreateBTree(int[] a) { TreeNode root = null; if (a[index] != '#') { root = new TreeNode(a[index]); i…
最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. int addDigi…
public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode(int x) { val = x; } } 打印代码 private void WriteTreeNode(TreeNode node) { StringBuilder stringBuilder=new StringBuilder(); if (node == null) { Console.W…
[题目] 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. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null…