スポンサーリンク

【LeetCode】107. Binary Tree Level Order Traversal II 解答・解説【Python】

スポンサーリンク
スポンサーリンク
この記事は約2分で読めます。

 

問題

原文

Given the root of a binary tree, return the bottom-up level order traversal of its nodes’ values. (i.e., from left to right, level by level from leaf to root).

 

Example 1:

Example 2:

Example 3:

 

Constraints:

  • The number of nodes in the tree is in the range [0, 2000].
  • -1000 <= Node.val <= 1000

 

内容

二分木rootが与えられるので、葉ノードから順に各ノードの値を返してください。

(左から右に、各階層ごとの葉ノードを返してください。)

 

※正しくない可能性があります。

 

解答

解答1:Python, BFS(幅優先探索)

 

 

 

解答2:

 

 

 

メモ・参考・感想

 

 

 

前:2351. First Letter to Appear Twice

次:637. Average of Levels in Binary Tree

LeetCode 解答・解説記事一覧

コメント