2019-01-26第二天

2019-01-26  本文已影响0人  织雾呀

今天刷leetcode时候刷到一道题,卧槽,想半天虽然有思路就是写不出,
题目:

二叉树的最小深度

后来百度了一下解法,卧槽卧槽卧槽槽,这么简单,我的基础功底真的是太烂了。。。
解法:


    public int minDepth(TreeNode root){
    if (root == null)
           return 0;
       if (root.left == null && root.right == null)
           return 1;
       if (root.left == null)
           return minDepth(root.right) + 1;
       if (root.right == null)
           return minDepth(root.left) + 1;

       return Math.min(minDepth(root.left) + 1, minDepth(root.right) + 1);
    }

妈呀,赶紧看看书吧,丢人

上一篇 下一篇

猜你喜欢

热点阅读