LeetCode Entry

94. Binary Tree Inorder Traversal

09.12.2023 easy 2023 kotlin

Inorder traversal

94. Binary Tree Inorder Traversal easy blog post substack youtube image.png

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/433

Problem TLDR

Inorder traversal

Intuition

Nothing special. For the iterative solution we can use Morris traversal.

Complexity

  • Time complexity: \(O(n)\)

  • Space complexity: \(O(n)\)

Code


  fun inorderTraversal(root: TreeNode?): List<Int> = root?.run {
    inorderTraversal(left) + listOf(`val`) + inorderTraversal(right)
  } ?: listOf<Int>()