6 lines Java Code, thanks to Prolog


  • 0
    P
    ···
    public class Solution {
        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.