< Summary

Information
Class: LeetCode.Algorithms.MinimumTimeDifference.MinimumTimeDifferenceSorting
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimumTimeDifference\MinimumTimeDifferenceSorting.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 43
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FindMinDifferenceInternal(...)100%44100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimumTimeDifference\MinimumTimeDifferenceSorting.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
 12namespace LeetCode.Algorithms.MinimumTimeDifference;
 13
 14/// <inheritdoc />
 15public class MinimumTimeDifferenceSorting : MinimumTimeDifferenceBase
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n log n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="timePoints"></param>
 22    /// <returns></returns>
 23    public override int FindMinDifferenceInternal(IList<string> timePoints)
 724    {
 725        var minutes = new int[timePoints.Count];
 26
 6227        for (var i = 0; i < minutes.Length; i++)
 2428        {
 2429            minutes[i] = (int)TimeSpan.Parse(timePoints[i]).TotalMinutes;
 2430        }
 31
 732        Array.Sort(minutes);
 33
 734        var minDifference = DayMinutes + minutes[0] - minutes[^1];
 35
 4836        for (var i = 0; i < minutes.Length - 1; i++)
 1737        {
 1738            minDifference = Math.Min(minDifference, minutes[i + 1] - minutes[i]);
 1739        }
 40
 741        return minDifference;
 742    }
 43}