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 ...
随机推荐
- Lemon OA第3篇:核心功能
对Lemon OA系统的核心功能进行梳理,分别介绍说明如下文. Portal页面 还是从用户主页开始说起: OA核心的功能就是流程,启动流程,办理流程,查看历史,3个常用功能都罗列在用户主页上,方便用 ...
- C# 在多线程环境中,进行安全遍历操作
本文以List作为操作对象MSDN官方给出的List的线程安全的说法:此类型的公共静态成员是线程安全的.但不能保证任何实例成员是线程安全的.只要不修改该集合,List 就可以同时支持多个阅读器.通过集 ...
- c/c++ 代码中使用sse指令集加速
使用SSE指令,首先要了解这一类用于进行初始化加载数据以及将暂存器的数据保存到内存相关的指令, 我们知道,大多数SSE指令是使用的xmm0到xmm8的暂存器,那么使用之前,就需要将数据从内存加载到这些 ...
- Java多线程——Lock&Condition
Lock比传统线程模型中的synchronized方式更加面向对象,与生活中的锁类似,锁本身也应该是一个对象.两个线程执行的代码片段要实现同步互斥的效果,它们必须用同一个Lock对象. package ...
- iOS:根据系统类型加载不同的xib
1.将 xib 文件名手动更改为 xxx~iphone.xib 和 xxx~ipad.xib 2.初始化时使用 [[xxx alloc] init] 即可,系统会自动判断系统类型并加载对应的 xib ...
- Fedora26 tftp-server设置
安装tftp-server yum install -y tftp-server 启动软件 systemctl start tftp.socket systemctl enable tftp.soc ...
- Material Design Support 8大控件介绍
TextInputLayout 显示提示信息 能够通过调用setError()在EditText以下显示一条错误信息 FloatingActionButton 悬浮操作按钮 Snackbar 相当于底 ...
- js eventLoop (使用chunk 同步变异步)
https://www.cnblogs.com/xiaohuochai/p/8527618.html 线程 javascript是单线程的语言,也就是说,同一个时间只能做一件事.而这个单线程的特性,与 ...
- Layer笔记
官网地址:http://layer.layui.com/hello.html 引入代码 <script src="jQuery的路径"></script> ...
- Thinkphp5笔记七:设置错误页面②
更加完美的去设置错误页面. 一.准备一个错误页面 error.html,位置:thinkphp\template\index\default\error.html ,准备把前段所有的错误提示都指向这里 ...