title: Use tail recursion to find maxDepth of Binary Tree
body: <p>I am making an effort to solve a problem <a href="https://leetcode.com/problems/maximum-depth-of-binary-tree/" rel="nofollow noreferrer">Maximum Depth of Binary Tree - LeetCode</a></p>
  <p>The problem is given as an exercise on tail recursion in a leetcode tutorial. <a href="https://leetcode.com/explore/learn/card/recursion-i/256/complexity-analysis/2374/" rel="nofollow noreferrer">tail recursion - LeetCode</a></p>
  <blockquote>
  <p>Given a binary tree, find its maximum depth.</p>
  <p>The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.</p>
  <p><strong>Note:</strong> A leaf is a node with no children.</p>
  <p><strong>Example:</strong></p>
  <p>Given binary tree <code>[3,9,20,null,null,15,7]</code>,</p>
  <pre><code>    3
     / \
    9  20
      /  \
     15   7
  </code></pre>
  <p>return its depth = 3.</p>
  </blockquote>
  <p>A standard solution which views the problem from the definition of level</p>
  <pre class="lang-py prettyprint-override"><code>class Solution:
      def maxDepth(self, root):
          &quot;&quot;&quot;
          :type root: TreeNode
          :rtype: int
          &quot;&quot;&quot; 
          if root is None: 
              return 0 
          else: 
              left_height = self.maxDepth(root.left) 
              right_height = self.maxDepth(root.right) 
              return max(left_height, right_height) + 1 
  </code></pre>
  <p>However, it's not a tail recursive</p>
  <blockquote>
  <p><strong>Tail recursion</strong> is a recursion where the recursive call is the final instruction in the recursion function. And there should be only <strong>one</strong> recursive call in the function.</p>
  </blockquote>
  <p>I read all other submissions and the discussions but did not find a tail recursive solution.</p>
  <p>How could solve the problem using tail recursion?</p>