数据结构之求二叉树的所有叶子和以及叶子总数
生活随笔
收集整理的這篇文章主要介紹了
数据结构之求二叉树的所有叶子和以及叶子总数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、題目
數據結構之求二叉樹的所有葉子和以及葉子總數2、代碼實現
tree.java package leetcode.chenyu.test;public class Tree {int val;Tree left;Tree right;Tree(int val) {this.val = val;} }package leetcode.chenyu.test;public class TreeTest {public static int sum = 0;public static int count = 0;public static void main(String[] args) {Tree t1 = new Tree(1);Tree t2 = new Tree(2);Tree t3 = new Tree(3);Tree t4 = new Tree(4);Tree t5 = new Tree(5);t1.left = t2;t1.right= t3;t2.left = t4;t3.left = t5;lastPrintf(t1);System.out.println("sum is" + sum + "count is " + count);}public static void lastPrintf(Tree head) {if (head == nul
總結
以上是生活随笔為你收集整理的数据结构之求二叉树的所有叶子和以及叶子总数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode之Sum of Left
- 下一篇: SVN之如何解决从一个svn路径下载项目