二叉树深度 给定一个二叉树,找出其最大深度。html
二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。node
说明: 叶子节点是指没有子节点的节点。mysql
示例: 给定二叉树 [3,9,20,null,null,15,7],ios
3
复制代码
/
9 20 /
15 7 返回它的最大深度 3 。sql
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int maxDepth(TreeNode root) {
if(root == null){
return 0;
}
int number = 1 ;
int leftDepth = 0,rightDepth = 0;
if(root.left != null){
leftDepth = maxDepth(root.left);
}
if(root.right != null){
rightDepth = maxDepth(root.right);
}
number += leftDepth > rightDepth ? leftDepth : rightDepth;
return number;
}
}
复制代码
The gender gap is also a confidence gap linkbash
以前有个朋友在写sql的时候碰到一个问题写sql查询的时候碰到了问题:ide
#sql1
select u.real_name,u.phone,b.order_no,b.amount as borrow_amount,b.create_time as borrow_time,r.id,r.user_id,r.borrow_id,r.state,r.amount as repay_amount,r.repay_time,r.penalty_amout,r.penalty_day,
b.fee ,b.real_amount,channel.name as channel_name,cmro.state as allotState,u.living_img,u.front_img,u.back_img, r.remark
from cl_borrow_repay r left join cl_user_base_info u on u.user_id=r.user_id join cl_borrow b on r.borrow_id=b.id
left join cl_user user2 on user2.id = u.user_id
left join cl_channel channel on user2.channel_id = channel.id
left join cl_manual_repay_order cmro on r.id = cmro.borrow_repay_id;
#sql2
select u.real_name,u.phone,b.order_no,b.amount as borrow_amount,b.create_time as borrow_time,r.id,r.user_id,r.borrow_id,r.state,r.amount as repay_amount,r.repay_time,r.penalty_amout,r.penalty_day,
b.fee ,b.real_amount,channel.name as channel_name,cmro.state as allotState,u.living_img,u.front_img,u.back_img, r.remark
from cl_borrow_repay r left join cl_user_base_info u on u.user_id=r.user_id join cl_borrow b on r.borrow_id=b.id
left join cl_user user2 on user2.id = u.user_id
left join cl_channel channel on user2.channel_id = channel.id
left join cl_manual_repay_order cmro on r.id = cmro.borrow_repay_id
ORDER BY r.id desc;
复制代码
sql1与sql2上基本(是否是应该用专业点的属于表示)没有改动,仅仅是在末位加上了order by ,可是最后的查询时间有着天壤之别。explain以后的结果以下 sql1: 优化
发如今Extra中多了Using temporary;Using filesort。 原来查询慢的缘由是由于使用orderby 后致使sql查询新增长了临时表及进行了文件排序。大量时间花在这上面了。 那么怎么优化? 一、能够考虑在条件中把主键id加入进去左右一块儿的条件,由于若是order by 的字段也在where里面这样就不会进入文件排序 二、能够参考一次mysql 优化 (Using temporary ; Using filesort) linkui
JVM发生频繁 CMS GC,罪魁祸首是这个参数! : link.spa