public int getDepth(TreeNode root) {
        if (root == null)
            return 0;
        if (map.containsKey(root))
            return map.get(root);
        int left = getDepth(root.left);
        int right = getDepth(root.right);
        int max = Math.max(left, right) + 1;
        map.put(root, max);
        return max;
    }