94-Binary-Tree-Inorder-Traversal

Sat 17 May 2025

https://leetcode.com/problems/binary-tree-inorder-traversal

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
    ans = []
    stack = []

    while root or stack:
      while root:
        stack.append(root)
        root = root.left
      root = stack.pop()
      ans.append(root.val)
      root = root.right

    return ans
new Solution().inorderTraversal()

Score: 5

Category: leetcode