[LeetCode刷题] Binary Tree Inorder Traversal
今天自己写了一下inorder traversal,写了一个挺neat的solution,感觉不错
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public List<Integer> inorderTraversal(TreeNode root) {
ArrayList<Integer> l = new ArrayList<Integer>();
if(root == null) {
return l;
}
l.addAll(inorderTraversal(root.left));
l.add(root.val);
l.addAll(inorderTraversal(root.right));
return l;
}
}