1.求二叉树的最小深度:

public class Solution {
public int run(TreeNode root) {
if(root==null)
return 0;
int l = run(root.left);
int r = run(root.right);
if(l==0 || r==0)
return l+r+1;
return Math.min(l,r)+1;
}
}
class TreeNode {
int val;
TreeNode left;
TreeNode right;
}

leetCode练习题的更多相关文章

  1. 【LeetCode练习题】Permutation Sequence

    Permutation Sequence The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and ...

  2. Leetcode练习题Remove Element

    Leetcode练习题Remove Element Question: Given an array nums and a value val, remove all instances of tha ...

  3. Arrays工具、二维数组以及LeetCode练习题

    1 Arrays PS:Arrays位于java.util包下 int binarySearch(type[] a, type key); 使用二分法查询 key 元素在 a 数组中的索引,如果数组不 ...

  4. 【LeetCode练习题】Remove Duplicates from Sorted List II

    Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...

  5. 【LeetCode练习题】Recover Binary Search Tree

    Recover Binary Search Tree Two elements of a binary search tree (BST) are swapped by mistake. Recove ...

  6. 【LeetCode练习题】Valid Palindrome

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  7. 【LeetCode练习题】Pow(x, n)

    Pow(x, n) Implement pow(x, n). 计算x的n次方. 解题思路: 考虑到n的值会很大,而且可为正可为负可为0,所以掉渣天的方法就是用递归了. 对了,这题也在<剑指off ...

  8. 【LeetCode练习题】Combination Sum

    Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combin ...

  9. 【LeetCode练习题】Minimum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  10. 【LeetCode练习题】Maximum Depth of Binary Tree

    Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...

随机推荐

  1. 【转】【MySQL】Mysql模糊查询like提速优化

    在使用msyql进行模糊查询的时候,很自然的会用到like语句,通常情况下,在数据量小的时候,不容易看出查询的效率,但在数据量达到百万级,千万级的时候,查询的效率就很容易显现出来.这个时候查询的效率就 ...

  2. Java如何比较两个数组?

    在Java中,如何比较两个数组? 示例 以下示例使用equals方法来检查两个数组是否相等. package com.yiibai; import java.util.*; public class ...

  3. C# 符合备忘录

    ~ 按位求补符:! 非逻辑运算符:% 求余运算符:^ 异或位运算符:& 且位运算符:|  或位运算符:* 既可以用作乘法符号,还可以表示为指针:+ 表示数学运算符相加:= 用来表示赋值操作:\ ...

  4. 使用selenium遇到java.lang.NoSuchMethodError: org.apache.xpath.XPathContext,排查

    初试selenium webdriver,运行小程序,抛如下错误:   java.lang.NoSuchMethodError: org.apache.xpath.XPathContext.<i ...

  5. 免费在线直播课,送给所有IT项目经理

     [免费在线直播课,送给所有IT项目经理]项目管理培训领域的老资格——光环国际,精心策划了一门一个半小时的在线直播课,送给所有辛苦的IT项目经理们.[直播主题]变化时代IT项目经理的成长要求[直播内容 ...

  6. Linux 系统安装配置PHP服务(源码安装)

    简介: PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广泛,主要 ...

  7. 错误 未能找到类型或命名空间名称"xxxxxx"的真正原因

    今天又被这问题撞上了,结果神奇般的解决了 谷歌了很久都没有找到真正有用的解决方案,所以在这儿写下,让更多的人看到 最根本的原因其实就是引用的问题,引用错了,然后VS在这上面提示又不够智能,所以大家被坑 ...

  8. C# 校验给定的ip地址是否合法

    函数用于检测ip地址格式是否合法,包括ip的组成格式,每隔段是否不超过255等,但这个函数不能验证这个ip地址是否可以ping通. /// <summary> /// 验证IP地址是否合法 ...

  9. WizNote分享笔记至博客

    右边的分享按钮  选中后出现如图所示  然后可以进行分享了    

  10. 原理分析之一:从JDBC到Mybatis

    原理分析之一:从JDBC到Mybatis Mybatis学习(一)原生态的JDBC编程总结 -----系列 深入浅出MyBatis-快速入门