C#C
C#3y ago
morry329#

✅ Cannot implicit convert type

I am working on this LC puzzle https://leetcode.com/problems/binary-tree-level-order-traversal/?envType=study-plan&id=level-1
Here's my progress:
public IList<IList<int>> LevelOrder(TreeNode root) {
        List<int> result = new List<int>();
        if(root == null){
            return result;
        }

        Queue<TreeNode> queue = new LinkedList<TreeNode>(); //ERROR HERE
        queue.Enqueue(root);
        while(queue != null){
            int size = queue.Count();
            List<int> curr = new List<int>();
            for(int i = 0; i < size; i++){
                TreeNode node = queue.Dequeue();
                curr.Add(node.val);
            }
            curr = result;
        }
        return result;
    }
`

I am getting the error Cannot implicitly convert type 'System.Collections.Generic.LinkedList<TreeNode>' to 'System.Collections.Generic.Queue<TreeNode>' (see the ERROR HERE in the code). Could anyone kindly tell me why?
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?