/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
import java.util.*;
public class Solution {
public ArrayList<Integer> inorderTraversal(TreeNode root) {
ArrayList<Integer> list = new ArrayList<Integer>();
if(root==null)
return list;
inorder(root,list);
return list;
}
public static void inorder(TreeNode root,ArrayList list){
if(root!=null){
inorder(root.left,list);
list.add(root.val);
inorder(root.right,list);
}
}
}
二叉树中序遍历
最新推荐文章于 2021-01-24 22:38:06 发布