| 11 | */ |
| 12 | |
| 13 | fun buildBinaryTree(preorder: List<Int>, inorder: List<Int>): TreeNode? { |
| 14 | val inorderIndexesMap = hashMapOf<Int, Int>() |
| 15 | val preorderIndex = intArrayOf(0) |
| 16 | // Populate the hash map with the inorder values and their indexes. |
| 17 | for (i in inorder.indices) { |
| 18 | inorderIndexesMap[inorder[i]] = i |
| 19 | } |
| 20 | // Build the tree and return its root node. |
| 21 | return buildSubtree(0, inorder.size - 1, preorder, inorder, preorderIndex, inorderIndexesMap) |
| 22 | } |
| 23 | |
| 24 | fun buildSubtree( |
| 25 | left: Int, |
nothing calls this directly
no test coverage detected