Easy to understand recursive Java solution.


  • 0
    O
    
        public List<Integer> inorderTraversal(TreeNode root) {
            if (root == null) return new ArrayList<Integer>();
            List<Integer> result = new ArrayList<Integer>();
            if (root.left != null) {
                result.addAll(inorderTraversal(root.left));
            }
            result.add(root.val);
            if (root.right != null) {
                result.addAll(inorderTraversal(root.right));
            }
            return result;
        }
    

Log in to reply
 

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