/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
var maxDepth = function(root) {
const q = [[root, 0]];
let max = 0;
while (q.length > 0) {
const [node, cnt] = q.shift();
if (node === null) continue;
max = Math.max(cnt + 1, max);
if (node.left !== null) q.push([node.left, cnt + 1]);
if (node.right !== null) q.push([node.right, cnt + 1]);
}
return max;
};