< Summary

Information
Class: LeetCode.Algorithms.DayOfTheWeek.DayOfTheWeekMath
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DayOfTheWeek\DayOfTheWeekMath.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 53
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%
DayOfTheWeek(...)100%22100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DayOfTheWeek\DayOfTheWeekMath.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.DayOfTheWeek;
 13
 14/// <inheritdoc />
 15public class DayOfTheWeekMath : IDayOfTheWeek
 16{
 1217    private readonly Dictionary<int, string> _weekDays = new()
 1218    {
 1219        { 0, "Monday" },
 1220        { 1, "Tuesday" },
 1221        { 2, "Wednesday" },
 1222        { 3, "Thursday" },
 1223        { 4, "Friday" },
 1224        { 5, "Saturday" },
 1225        { 6, "Sunday" }
 1226    };
 27
 28    /// <summary>
 29    ///     Time complexity - O(1)
 30    ///     Space complexity - O(1)
 31    /// </summary>
 32    /// <param name="day"></param>
 33    /// <param name="month"></param>
 34    /// <param name="year"></param>
 35    /// <returns></returns>
 36    public string DayOfTheWeek(int day, int month, int year)
 1237    {
 1238        if (month < 3)
 539        {
 540            month += 12;
 541            year -= 1;
 542        }
 43
 1244        var k = year % 100;
 1245        var j = year / 100;
 46
 1247        var h = (day + (13 * (month + 1) / 5) + k + (k / 4) + (j / 4) + (5 * j)) % 7;
 48
 1249        var dayOfWeek = (h + 5) % 7;
 50
 1251        return _weekDays[dayOfWeek];
 1252    }
 53}