Skip to content

Commit 3eadda0

Browse files
committed
빅오 추가
1 parent 3e80c0b commit 3eadda0

File tree

1 file changed

+1
-2
lines changed
  • construct-binary-tree-from-preorder-and-inorder-traversal

1 file changed

+1
-2
lines changed

construct-binary-tree-from-preorder-and-inorder-traversal/jdalma.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@ class `construct-binary-tree-from-preorder-and-inorder-traversal` {
1717
/**
1818
* preorder에서 조회한 부모 노드의 값은 inorder의 중간에 위치한다.
1919
* 그 중간 위치 기준으로 왼쪽 노드, 오른쪽 노드로 분리하여 재귀적으로 탐색할 수 있다.
20+
* 시간복잡도: O(n), 공간복잡도: O(n)
2021
*/
2122
private fun traversal(
2223
preorder: IntArray, inorder: IntArray, inorderIndices: Map<Int, Int>,
2324
preStart: Int = 0, inStart: Int = 0, inEnd: Int = inorder.size - 1
2425
): TreeNode? {
2526
if (preStart > preorder.size - 1 || inStart > inEnd) {
26-
println("preStart: $preStart, inStart: $inStart, inEnd: $inEnd --- return null")
2727
return null
2828
}
2929
val value = preorder[preStart]
3030
val rootIndexInInorder = inorderIndices[value]!!
3131

32-
println("value: $value, preStart: $preStart, rootIndexInInorder: $rootIndexInInorder, inStart: $inStart, inEnd: $inEnd")
3332
return TreeNode(value).apply {
3433
this.left = traversal(
3534
preorder, inorder, inorderIndices,

0 commit comments

Comments
 (0)