< Summary

Information
Class: LeetCode.Algorithms.MinimumDominoRotationsForEqualRow.MinimumDominoRotationsForEqualRowGreedy
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimumDominoRotationsForEqualRow\MinimumDominoRotationsForEqualRowGreedy.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 61
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
MinDominoRotations(...)100%44100%
TryTarget(...)100%1010100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimumDominoRotationsForEqualRow\MinimumDominoRotationsForEqualRowGreedy.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.MinimumDominoRotationsForEqualRow;
 13
 14/// <inheritdoc />
 15public class MinimumDominoRotationsForEqualRowGreedy : IMinimumDominoRotationsForEqualRow
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="tops"></param>
 22    /// <param name="bottoms"></param>
 23    /// <returns></returns>
 24    public int MinDominoRotations(int[] tops, int[] bottoms)
 325    {
 326        var result = TryTarget(tops, bottoms, tops[0]);
 27
 328        if (result != -1 || tops[0] == bottoms[0])
 229        {
 230            return result;
 31        }
 32
 133        return TryTarget(tops, bottoms, bottoms[0]);
 334    }
 35
 36    private static int TryTarget(int[] tops, int[] bottoms, int target)
 437    {
 438        var topRotations = 0;
 439        var bottomRotations = 0;
 40
 4841        for (var i = 0; i < tops.Length; i++)
 2242        {
 2243            if (tops[i] != target && bottoms[i] != target)
 244            {
 245                return -1;
 46            }
 47
 2048            if (tops[i] != target)
 749            {
 750                topRotations++;
 751            }
 52
 2053            if (bottoms[i] != target)
 854            {
 855                bottomRotations++;
 856            }
 2057        }
 58
 259        return Math.Min(topRotations, bottomRotations);
 460    }
 61}