leetcode-94-easy

Binary Tree Inorder Traversal

public List<Integer> inorderTraversal(TreeNode root) {
    List<Integer> list = new ArrayList<>();
    t(root, list);
    return list;
}

public void t(TreeNode root, List<Integer> list) {
    if (root == null) return;

    t(root.left, list);
    list.add(root.val);
    t(root.right, list);
}
posted @ 2022-10-13 18:01  iyiluo  阅读(11)  评论(0)    收藏  举报