Given a binary tree, return the inorder traversal of its nodes ' values.
For example:
Given binary Tree {1,#,2,3} ,
1 2 / 3
Return [1,3,2] .
Note: Recursive solution is trivial, could do it iteratively?
Confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ.
Has you met this question in a real interview? Solution:
1 /**2 * Definition for binary tree3 * public class TreeNode {4 * int val;5 * TreeNode left;6 * TreeNode right;7 * TreeNode (int x) {val = x;}8 * }9 */Ten Public classSolution { One PublicList<integer>inordertraversal (TreeNode root) { AList<integer> nodeList =NewArraylist<integer>(); - inorderrecur (nodelist,root); - the returnnodeList; - - } - + Public voidInorderrecur (list<integer>nodeList, TreeNode curnode) { - if(curnode==NULL)return; + A inorderrecur (nodelist,curnode.left); at Nodelist.add (curnode.val); - inorderrecur (nodelist,curnode.right); - - return; - - } in}
Leetcode-binary Tree inorder Traversal