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 ...
随机推荐
- tornado上传大文件以及多文件上传
tornado上传大文件问题解决方法 tornado默认上传限制为低于100M,但是由于需要上传大文件需求,网上很多说是用nginx,但我懒,同时不想在搞一个服务了. 解决方法: server = H ...
- 第三百五十九节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)介绍以及安装
第三百五十九节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)介绍以及安装 elasticsearch(搜索引擎)介绍 ElasticSearch是一个基于 ...
- c# 生成随机时间
Random random = new Random((int)(DateTime.Now.Ticks)); ; ) { , ); , ); , ); string tempStr = string. ...
- 手机web——自适应网页设计(html/css控制)http://mobile.51cto.com/ahot-409516.htm
http://mobile.51cto.com/ahot-409516.htm 一. 允许网页宽度自动调整: "自适应网页设计"到底是怎么做到的? 其实并不难. 首先,在网页代码的 ...
- python_不用循环打印1-1000
题目:屏幕上打印1-1000这1000个数, 不许使用循环语句/条件语句,不许使用?:算符. 不许在源代码中用列举输出语句的办法傻打,比如一千个print语句不行,不再赘述其他傻打行为, 大家都能领会 ...
- mysql字段类型对应javabean属性
来吧 我们一起看下图,就能明白了.
- EF5+MVC4系列(8) ActionResult的返回值
我们在MVC的代码中,经常会看到这样的一个 代码 可能有人会有疑问,既然我定义的是ActionResult,为什么返回值会是View方法呢? 其实这个View方法的返回值的类型是ActionResul ...
- tophat-fusion 鉴定融合基因
tophat-fusion 是一款利用RNA_seq 数据鉴定融合基因的工具,官网链接如下: http://ccb.jhu.edu/software/tophat/fusion_index.shtml ...
- Kubeadm 安装
version 1.7.0 已解决: echo "1" > /proc/sys/net/bridge/bridge-nf-call-iptables error: faile ...
- MYSQL类型与JAVA类型对应表
MYSQL类型与JAVA类型对应表: 类型名称 显示长度 数据库类型 JAVA类型 JDBC类型索引(int) VARCHAR L+N VARCHAR java.lang.String 12 CHAR ...