1231. [S/W 문제해결 기본] 9일차 - 중위순회

dannyp0930·2021년 9월 23일
0

SW Expert Academy

목록 보기
13/14
post-thumbnail

출처 : 링크텍스트

1. 풀이방법

중위 순회를 이해하는 기본적인 문제이다.

2. 코드

def inorder(t, idx):
    temp = ''
    if idx*2 < len(t):
        temp += inorder(t, idx*2)
    temp += t[idx]
    if idx*2 + 1 < len(t):
        temp += inorder(t, idx*2+1)

    return temp

for test_case in range(1, 11):
    N = int(input())
    lst = []
    tree = [0] * (N+1)
    for _ in range(N):
        s = list(input().split())
        tree[int(s[0])] = s[1]
    a = inorder(tree, 1)

    print("#{}".format(test_case), a)
profile
Newbie 개발자

0개의 댓글