var maxDepth = function(root) {
let res = 0
const dfs = (n, level)=>{
if(!n) {return}
if(!n.right && !n.left){
res = Math.max(res, level)
}
dfs(n.left ,level+1)
dfs(n.right ,level+1)
}
dfs(root,1)
return res
};
老師請問為什麼以下二行level+1 改成level++就不行,level+1 和level++有什麼不一樣嗎?
dfs(n.left ,level+1)
dfs(n.right ,level+1)