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. 计算机网络——链路层协议

    一. 链路层的功能 可靠交付:在高差错的链路,如无线链路,可以进行可靠交付:对于其它的有线,可以是多余的: 流量控制:防止接收方的缓存区溢出,帧丢失: 差错检测与差错纠正:在硬件上实现了: 二.多路访 ...

  3. e802. 创建一个位置大小的JProgressBar组件

    A progress bar with an unknown maximum typically displays an animation until the task is complete. N ...

  4. JAVA对于程序的运行的一种解说

    main方法,正如注释所说,这是程序开始执行的第一行.对于一个Java应用程序来说,main方法是必需的,Java解释器在没有生成任何对象的情况下,以main作为入口来执行程序.每个类中可以定义多个方 ...

  5. 【Hibernate步步为营】--最后的集合映射

    上篇文章具体讨论了组合对象映射的原理.它事实上指的是怎样将对象模型中的组合关系映射到关系模型中,它是通过使用Hibernate提供的<component>标签来实现的,并须要在该标签中加入 ...

  6. Java处理JSON的工具类(List、Map和JSON之间的转换)——依赖jsonlib支持Map嵌套

    原文链接:http://www.itjhwd.com/java_json/ 代码 package com.itjh.mmp.util; import java.io.BufferedReader; i ...

  7. python模块之 - subprocess执行unix/linux命令

    subprocess模块提供了一种一致的方法来创建和处理附加进程,与标准库中的其它模块相比,提供了一个更高级的接口,subprocess模块用来生成子进程,并可以通过管道连接它们的输入/输出/错误,以 ...

  8. autofac 实例生命周期

    转自逆心博客园 autofac 实例生命周期 实例生命周期决定在同一个服务的每个请求的实例是如何共享的. 当请求一个服务的时候,Autofac会返回一个单例 (single instance作用域), ...

  9. u3d changeTexs

    using UnityEngine; using System.Collections; using System.Collections.Generic; public class CTex : M ...

  10. memcached监控工具

    最简单和最直接的方式是在启动memcached的时候加入-vv参数,从而在控制台打印每次客户端的请求和相应,这非常适合开发.另外一种较为直接的方式是通过telnet进行查看,例如:若server为本机 ...