leetCode练习题
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练习题的更多相关文章
- 【LeetCode练习题】Permutation Sequence
Permutation Sequence The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and ...
- Leetcode练习题Remove Element
Leetcode练习题Remove Element Question: Given an array nums and a value val, remove all instances of tha ...
- Arrays工具、二维数组以及LeetCode练习题
1 Arrays PS:Arrays位于java.util包下 int binarySearch(type[] a, type key); 使用二分法查询 key 元素在 a 数组中的索引,如果数组不 ...
- 【LeetCode练习题】Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
- 【LeetCode练习题】Recover Binary Search Tree
Recover Binary Search Tree Two elements of a binary search tree (BST) are swapped by mistake. Recove ...
- 【LeetCode练习题】Valid Palindrome
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- 【LeetCode练习题】Pow(x, n)
Pow(x, n) Implement pow(x, n). 计算x的n次方. 解题思路: 考虑到n的值会很大,而且可为正可为负可为0,所以掉渣天的方法就是用递归了. 对了,这题也在<剑指off ...
- 【LeetCode练习题】Combination Sum
Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combin ...
- 【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 ...
- 【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 ...
随机推荐
- (笔记)Ubuntu下安装arm-linux-gcc-4.4.3.tar.gz (交叉编译环境)
参考了前人的成果,结合自己实践,arm-linux-gcc-4.4.3.tar.gz的下载地址为:http://ishare.iask.sina.com.cn/f/13836544.html?from ...
- SpringMVC系列(十三)异常处理
一.简介 • Spring MVC 通过 HandlerExceptionResolver 处理程序的异常,包括 Handler 映射.数据绑定以及目标方法执行时发生的异常.• SpringMVC 提 ...
- Maven是一个项目管理工具
Maven是一个项目管理工具,它包含了一个项目对象模型 (Project Object Model),一组标准集合,一个项目生命周期(Project Lifecycle),一个依赖管理系统(Depen ...
- autofac解析Mvc和Webapi的坑
我们在项目中很早就开始使用autofac,也以为知道与mvc和webapi集成的做法. var builder = new ContainerBuilder(); // Mvc Register bu ...
- 回想sql语句中的各种连接
1. 内连接(Inner Join) 内连接是最常见的一种连接,它页被称为普通连接,而E.FCodd最早称之为自然连接. 以下是ANSI SQL-92标准 select * from t_ins ...
- ping失败的结果分析
①Request timed out 这是大家经常碰到的提示信息,很多文章中说这是对方机器置了过滤ICMP数据包,从上面工作过程来看,这是不完全正确的,至少有下几种情况. a. 对方已关机,或者网络上 ...
- 安装drools workbench
从drools官网下载tomcat7版本的Drools Tomcat 7+ WAR, Workbench,实际就是一个war包,需要严格按照里面的readme的要求,配置好tomcat才可以运行起来 ...
- C# 使用 Task 替换 ThreadPool ,异步监测所有线程(任务)是否全部执行完毕
using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections.Generic; using System.T ...
- MySQL提示“错误2:系统找不到指定文件”
一.问题原因 个人猜测可能是因为安装的是绿色版MySQL,然后在系统变量path中加入了解压后的路径.后续操作上没有跳转到解压后的路径,而是直接在cmd的默认路径下新建MySQL的服务,所以导致此问题 ...
- Xcode : svn 无法上传静态库(.a)文件
1.打开终端,输入cd,空格,然后将需要上传的.a文件所在的文件夹(不是.a文件)拖拽到终端(此办法无需输入繁琐的路径,快捷方便) ,回车:2.之后再输入如下命令:svn add xxx.a,回车:3 ...