Given the root of a binary tree, return the inorder traversal of its nodes’ values.
Example 1:
1 | Input: root = [1,null,2,3] |
Example 2:
1 | Input: root = [] |
Example 3:
1 | Input: root = [1] |
Example 4:
1 | Input: root = [1,2] |
Example 5:
1 | Input: root = [1,null,2] |
二元樹尋訪應該是樹類最基本題目了,尋訪分三種,前序,中序,後序,依照值(root.val)位置決定是哪種。
1 | preorder: 中->左->右 |
而題目需要中序,所以可以寫成
1 | def inOrder(root): |
如果你覺得這篇文章很棒,請你不吝點讚 (゚∀゚)