Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 29, 2014 01:00
Show Gist options
  • Save Cee/c3eb000c888488516257 to your computer and use it in GitHub Desktop.
Save Cee/c3eb000c888488516257 to your computer and use it in GitHub Desktop.
/**
* 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) {
List<Integer> ret = new ArrayList<Integer>();
if (root != null){
if (root.left != null) ret.addAll(inorderTraversal(root.left));
ret.add(root.val);
if (root.right != null) ret.addAll(inorderTraversal(root.right));
}
return ret;
}
}
@Cee
Copy link
Author

Cee commented May 29, 2014

坑爹的List。。。。初始化哦~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment