1ms Java Simple Solution


  • 2
    B

    public class Solution {

    List<Integer> list;
    public List<Integer> inorderTraversal(TreeNode root) {
        list = new ArrayList<Integer>();
        if(root==null)
            return list;
        inorder(root);
        return list;
    }
    
    public void inorder(TreeNode root){
        
        
        if(root.left!=null){
              inorder(root.left);
        }
        list.add(root.val);
          
        if(root.right!=null){
              inorder(root.right);
        }
        
    }
    

    }


Log in to reply
 

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