C# Accepted Solution using recursion


  • 0
    J
    private IList<int> list = new List<int>();
        
        public IList<int> InorderTraversal(TreeNode root) 
        {
            if (root == null) return list;
            Helper(root);
            return list;
        }
        
        private void Helper(TreeNode root)
        {
            if (root == null) return;
            Helper(root.left);
            list.Add(root.val);
            Helper(root.right);
        }
    

Log in to reply
 

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