[백준/파이썬] 2263번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 2263번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
백준 2263번 문제를 풀이합니다.
코드
`python import sys; read = sys.stdin.readline
sys.setrecursionlimit(1_000_000)
results = []
n = int(read()) in_order = list(map(int, read().split())) in_idx = {in_order[i]: i for i in range(n)} post_order = list(map(int, read().split()))
def insert_from_in_order(in_start, in_end, post_start, post_end): if in_start > in_end or post_start > post_end: return
results.append(post_order[post_end])
root_idx = in_idx[post_order[post_end]]
left_size = root_idx - in_start
insert_from_in_order(in_start, root_idx - 1,
post_start, post_start + left_size - 1)
insert_from_in_order(root_idx + 1, in_end,
post_start + left_size, post_end - 1)
insert_from_in_order(0, n - 1, 0, n - 1)
print(‘ ‘.join(map(str, results)))
```
설명
저장소의 기존 제출 코드를 기준으로 정리한 풀이입니다.
댓글남기기