#104.Maximum Depth of Binary Tree [LeetCode Grind 75 in Java]

[Problem Link] https://leetcode.com/problems/maximum-depth-of-binary-tree/

class Solution {
    public int maxDepth(TreeNode root) {
        if(root == null) return 0;
        //BFS traversal
        Queue<TreeNode> q = new LinkedList<TreeNode>();
        q.add(root);

        int depth = 0;
        while(!q.isEmpty()){
            int sz = q.size();
            depth ++;
            while(sz -- > 0){
                TreeNode curr = q.poll();
                if(curr.left != null) q.add(curr.left);
                if(curr.right != null) q.add(curr.right);
            }

        }

        return depth;
    }
}