Java recursive solution


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

Log in to reply
 

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