Depth of a Value
You are given the root of a binary tree. The root has depth 0, its children depth 1, and so on. Return the depth of the node whose value is target, or -1 if no node has that value. All values are distinct.
Trees appear in the tests in level order, with null for a missing child, like [3,9,20,null,null,15,7]. Each node is a TreeNode with .val, .left and .right; the class is already defined for you.
Example 1
root [3,9,20,null,null,15,7]
target 15
returns 2
3 -> 20 -> 15 is two steps down.
Constraints
0 <= number of nodes <= 100-100 <= node.val <= 100- Values are distinct.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.