use recursion in Java


  • 0
    L

    public class Solution {
    public List<Integer> list = new ArrayList<>();
    public List<Integer> inorderTraversal(TreeNode root) {

        if(root==null){return list;}
        
        if(root.left!=null){
            inorderTraversal(root.left);
        }
        list.add(new Integer(root.val));
        
        if(root.right!=null){
            inorderTraversal(root.right);
        }
        return list;
    }
    

    }


Log in to reply
 

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