simple Accepted code


  • 0
    L
    public class Solution {
        
        List<Integer> list = new ArrayList<Integer>();
        
        public List<Integer> preorderTraversal(TreeNode root) {
            if(root == null) return list;
            
            list.add(root.val);
            preorderTraversal(root.left);
            preorderTraversal(root.right);
            
            return list;
        }
    }
    

    Why are other people making it so complicated?


Log in to reply
 

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