二叉樹深度 給定一個二叉樹,找出其最大深度。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: 優化
sql2:發如今Extra中多了Using temporary;Using filesort。 原來查詢慢的緣由是由於使用orderby 後致使sql查詢新增長了臨時表及進行了文件排序。大量時間花在這上面了。 那麼怎麼優化? 一、能夠考慮在條件中把主鍵id加入進去左右一塊兒的條件,由於若是order by 的字段也在where裏面這樣就不會進入文件排序 二、能夠參考一次mysql 優化 (Using temporary ; Using filesort) linkui
JVM發生頻繁 CMS GC,罪魁禍首是這個參數! : link.spa