Beat 100% User using DFS approach and Typescript
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires finding the value of the leftmost node at the deepest level of a b
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires finding the value of the leftmost node at the deepest level of a binary tree.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTo solve this problem, we can perform a depth-first search (DFS) traversal of the binary tree. During the traversal, we keep track of the maximum depth reached and update the leftmost value encountered at that depth. We start with an initial maximum depth of -1 and traverse the tree, updating the maximum depth and leftmost value whenever we encounter a node at a greater depth than the current maximum depth.\n# Complexity\n- Time complexity:O(n), where n is the number of nodes in the binary tree. We visit each node once.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(h), where h is the height of the binary tree. This space is used for the call stack during the depth-first search traversal.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n *     val: number\n *     left: TreeNode | null\n *     right: TreeNode | null\n *     constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n *         this.val = (val===undefined ? 0 : val)\n *         this.left = (left===undefined ? null : left)\n *         this.right = (right===undefined ? null : right)\n *     }\n * }\n */\n\nlet maxDepth: number;\nlet bottomLeftValue: number;\n\nfunction findBottomLeftValue(root: TreeNode | null): number {\n    maxDepth = -1;\n    bottomLeftValue = 0;\n    dfs(root, 0);\n    return bottomLeftValue;\n}\n\nfunction dfs(current: TreeNode, depth: number) {\n    if (current === null) {\n        return;\n    };\n    if (depth > maxDepth) {\n        maxDepth = depth;\n        bottomLeftValue = current.val;\n    }\n    dfs(current.left, depth + 1);\n    dfs(current.right, depth + 1);\n}\n```
['TypeScript']