94 Binary Tree Inorder Traversal (recursive)
Given the root
of a binary tree, return the inorder traversal of its nodes' values.
Example 1:
Example 2:
Example 3:
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> result = new ArrayList<Integer>();
helper(root, result);
return result;
}
public static void helper(TreeNode root, List<Integer> result){
if (root == null){
return;
}
helper(root.left, result);
result.add(root.val);
helper(root.right, result);
return;
}
}
/*
1
\
2
/
3
inorder left, root, right
root.left
root
root.right
*/