题目:
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]
.
代码:
public class Solution {public static ArrayList<Integer> listResult = new ArrayList<Integer>();public static ArrayList<Integer> inorderTraversal(TreeNode root) {listResult.clear();if(root!=null){getNode(root);}return listResult;}public static void getNode(TreeNode root){if(root == null){return;}getNode(root.left);listResult.add(root.val);getNode(root.right);} }
注意事项
1. List 和 ArrayList的使用
2. ArrayList在使用前需要先清空