< Summary

Information
Class: LeetCode.Core.Models.ListNode
Assembly: LeetCode.Core
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode.Core\Models\ListNode.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 69
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
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%
ToListNode(...)100%11100%
ToCycledListNode(...)100%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode.Core\Models\ListNode.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 singly-linked list
 18/// </summary>
 19public class ListNode
 20{
 21    public ListNode? next;
 22
 23    public int val;
 24
 123325    public ListNode(int val = 0, ListNode? next = null)
 123326    {
 123327        this.next = next;
 123328        this.val = val;
 123329    }
 30
 31    public static ListNode? ToListNode(int[] array)
 34332    {
 143533        return array.Reverse().Aggregate<int, ListNode?>(null, (next, val) => new ListNode(val, next));
 34334    }
 35
 36    public static ListNode? ToCycledListNode(int[] array, int cyclePosition)
 1837    {
 1838        var head = ToListNode(array);
 39
 1840        if (head == null || cyclePosition < 0)
 641        {
 642            return head;
 43        }
 44
 2445        ListNode? lastNode = head, cycleNode = null;
 46
 14047        for (var index = 0; lastNode.next != null; index++)
 5848        {
 5849            if (index == cyclePosition)
 1050            {
 1051                cycleNode = lastNode;
 1052            }
 53
 5854            lastNode = lastNode.next;
 5855        }
 56
 1257        if (cyclePosition == array.Length - 1)
 258        {
 259            cycleNode = lastNode;
 260        }
 61
 1262        if (cycleNode != null)
 1263        {
 1264            lastNode.next = cycleNode;
 1265        }
 66
 1267        return head;
 1868    }
 69}