Created
May 20, 2014 03:20
-
-
Save honux77/3ccb54abb34c16d81815 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://oj.leetcode.com/problems/binary-tree-inorder-traversal/