A Java Solution (Beat 96%)


  • 0

    public class Solution {

    List<Integer> inOd = new ArrayList<>(); 
    public List<Integer> inorderTraversal(TreeNode root) {
        if (root != null) inPath(root); 
        return inOd;     
    }
    
    private void inPath (TreeNode root){
        if (root == null) return;
        if (root.left != null) { inPath(root.left); }
        inOd.add(root.val); 
        if (root.right != null) { inPath(root.right); }
    }
    

    }


Log in to reply
 

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