< Summary

Information
Class: LeetCode.Core.Models.TreeNode
Assembly: LeetCode.Core
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode.Core\Models\TreeNode.cs
Line coverage
100%
Covered lines: 40
Uncovered lines: 0
Coverable lines: 40
Total lines: 85
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ToTreeNode(...)100%1414100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode.Core\Models\TreeNode.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 a binary tree node
 18/// </summary>
 19public class TreeNode
 20{
 21    public TreeNode? left;
 22
 23    public TreeNode? right;
 24
 25    public int val;
 26
 278927    public TreeNode(int? val = null, TreeNode? left = null, TreeNode? right = null)
 278928    {
 278929        this.left = left;
 278930        this.right = right;
 278931        this.val = val ?? 0;
 278932    }
 33
 34    public static TreeNode? ToTreeNode(IEnumerable<int?> values)
 55635    {
 55636        using var enumerator = values.GetEnumerator();
 37
 55638        if (!enumerator.MoveNext() || enumerator.Current == null)
 6639        {
 6640            return null;
 41        }
 42
 49043        var root = new TreeNode(enumerator.Current.Value);
 49044        var queue = new Queue<TreeNode>();
 45
 49046        queue.Enqueue(root);
 47
 188248        while (queue.Count > 0)
 188249        {
 188250            var current = queue.Dequeue();
 51
 188252            if (enumerator.MoveNext())
 150653            {
 150654                if (enumerator.Current.HasValue)
 114655                {
 114656                    current.left = new TreeNode(enumerator.Current.Value);
 57
 114658                    queue.Enqueue(current.left);
 114659                }
 150660            }
 61            else
 37662            {
 37663                break;
 64            }
 65
 150666            if (enumerator.MoveNext())
 139267            {
 139268                if (!enumerator.Current.HasValue)
 36169                {
 36170                    continue;
 71                }
 72
 103173                current.right = new TreeNode(enumerator.Current.Value);
 74
 103175                queue.Enqueue(current.right);
 103176            }
 77            else
 11478            {
 11479                break;
 80            }
 103181        }
 82
 49083        return root;
 55684    }
 85}