A Java solution, beats 96.48%


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

  • 2
    E

    didn't the problem state that no recursion!


Log in to reply
 

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