Simple Recursive Solution in JAVA

  • 0
    public class Solution {
        public List<Integer> inorderTraversal(TreeNode root) {
            List<Integer> list = new ArrayList<Integer>();
            return inorderTraversal(root, list);
        List<Integer> inorderTraversal(TreeNode root, List<Integer> list){
            if(root == null) return list;
            inorderTraversal(root.left, list);
            inorderTraversal(root.right, list);
            return list;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.