< Summary

Information
Class: LeetCode.Core.Models.Node
Assembly: LeetCode.Core
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode.Core\Models\Node.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 70
Line coverage: 100%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
.ctor(...)100%11100%
ToNode(...)91.66%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode.Core\Models\Node.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12// ReSharper disable InconsistentNaming
 13
 14namespace LeetCode.Core.Models;
 15
 16/// <summary>
 17///     Definition for an n-ary tree node
 18/// </summary>
 19public class Node
 20{
 21    public IList<Node>? children;
 22
 23    public int val;
 24
 325    public Node() : this(0) { }
 26
 16427    public Node(int? val = null, IList<Node>? children = null)
 16428    {
 16429        this.children = children;
 16430        this.val = val ?? 0;
 16431    }
 32
 33    public static Node? ToNode(int?[] values)
 2234    {
 2235        if (values.Length == 0 || values[0] == null)
 636        {
 637            return null;
 38        }
 39
 1640        var root = new Node(values[0]);
 41
 1642        var queue = new Queue<Node>();
 43
 1644        queue.Enqueue(root);
 45
 1646        var i = 2;
 47
 12048        while (queue.Count > 0 && i < values.Length)
 10449        {
 10450            var current = queue.Dequeue();
 51
 10452            current.children = [];
 53
 24854            while (i < values.Length && values[i] != null)
 14455            {
 14456                var child = new Node(values[i]);
 57
 14458                current.children.Add(child);
 59
 14460                queue.Enqueue(child);
 61
 14462                i++;
 14463            }
 64
 10465            i++;
 10466        }
 67
 1668        return root;
 2269    }
 70}