/*
 * function TreeNode(x) {
 *   this.val = x;
 *   this.left = null;
 *   this.right = null;
 * }
 */

/**
  * 
  * @param root TreeNode类 
  * @return int整型
  */
function maxDepth(root) {
    // write code here
    // console.log(root);
    let node = { ...root };
    console.log(node);
    console.log({ ...node.left }.right)
    console.log({ ...{ ...node.left }.left }.left)
    //console.log({...node.left}.right)
    function maxDepth(node, cnt) {
        if (node == null) {
            return 0;
        }
        let max = cnt;
        if (node.left) {
            let l = maxDepth(node.left, cnt + 1);
            if (l > max) {
                // 若此次深搜返回层数大于记录层数,则覆盖
                max = l;
            }
        }
        if (node.right) {
            let r = maxDepth(node.right, cnt + 1);
            if (r > max) {
                // 若此次深搜返回层数大于记录层数,则覆盖
                max = r;
            }
        }
        return max;
    }
    let ans = maxDepth(root, 1);
    return ans;
}
module.exports = {
    maxDepth: maxDepth
};