白駿5639バイナリ検索ツリー/python
1294 ワード
出力
->ルートノード
import sys
sys.setrecursionlimit(10 ** 6)
preorder = []
def postorder(start, end):
if start >= end:
return
root = preorder[start]
if preorder[end - 1] <= root:
postorder(start + 1, end)
print(root)
return
idx = 0
for i in range(start + 1, end):
if preorder[i] > root:
idx = i
break
postorder(start + 1, idx)
postorder(idx, end)
print(root)
while True:
try:
preorder.append(int(sys.stdin.readline()))
except:
break
postorder(0, len(preorder))
Reference
この問題について(白駿5639バイナリ検索ツリー/python), 我々は、より多くの情報をここで見つけました https://velog.io/@stthunderl/백준-5639-이진-검색-트리-pythonテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol