Skip to content

Instantly share code, notes, and snippets.

@honux77
Created May 20, 2014 03:20
Show Gist options
  • Select an option

  • Save honux77/3ccb54abb34c16d81815 to your computer and use it in GitHub Desktop.

Select an option

Save honux77/3ccb54abb34c16d81815 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 ArrayList<Integer> inorderTraversal(TreeNode root) {
ArrayList<Integer> ret = new ArrayList<Integer> ();
_inorder(root, ret);
return ret;
}
private void _inorder(TreeNode root, ArrayList<Integer> list) {
if(root == null)
return;
_inorder(root.left, list);
list.add(root.val);
_inorder(root.right, list);
}
}
@honux77
Copy link
Copy Markdown
Author

honux77 commented May 20, 2014

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