C#C
C#3y ago
morry329#

✅ A bunch of syntax errors

I am trying to solve this puzzle https://leetcode.com/problems/n-ary-tree-preorder-traversal/
I got a couple of syntax errors at the foreach loop (like I am missing ; or , etc), but I have no idea how to apply the variable val assigned by LeetCode. Could anyone kindly point me some directions?

public class Solution {
    public IList<int> Preorder(Node root) {
        List<int> ans = new List<int>();
        if(root == null){
            return ans;
        }
        Helper(root, ans);
        return ans;
    }

    public void Helper(Node root, List<int> ans){
       
        foreach(Node root.value in root.children){
            Helper(root, ans);
        }
    }
}
`
LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Was this page helpful?