Optimized Java Solution beats 97%


  • 2
    public class Solution {
        List<Integer> res = new ArrayList<>();
        public List<Integer> inorderTraversal(TreeNode root) {
            if(root==null) 
                 return res;
            inorderTraversal(root.left);
            res.add(root.val);
            inorderTraversal(root.right);
            return res;
        }
    }
    

  • 0
    D

    thats recursion still...


Log in to reply
 

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