< Summary

Information
Class: LeetCode.Algorithms.SpecialPositionsInBinaryMatrix.SpecialPositionsInBinaryMatrixBruteForce
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SpecialPositionsInBinaryMatrix\SpecialPositionsInBinaryMatrixBruteForce.cs
Line coverage
95%
Covered lines: 38
Uncovered lines: 2
Coverable lines: 40
Total lines: 79
Line coverage: 95%
Branch coverage
95%
Covered branches: 19
Total branches: 20
Branch coverage: 95%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
NumSpecial(...)100%66100%
IsSpecial(...)92.85%141491.66%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SpecialPositionsInBinaryMatrix\SpecialPositionsInBinaryMatrixBruteForce.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 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.SpecialPositionsInBinaryMatrix;
 13
 14/// <inheritdoc />
 15public sealed class SpecialPositionsInBinaryMatrixBruteForce : ISpecialPositionsInBinaryMatrix
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m * n * (m + n))
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="mat"></param>
 22    /// <returns></returns>
 23    public int NumSpecial(int[][] mat)
 224    {
 225        var result = 0;
 26
 227        var m = mat.Length;
 228        var n = mat[0].Length;
 29
 1630        for (var i = 0; i < m; i++)
 631        {
 4832            for (var j = 0; j < n; j++)
 1833            {
 1834                if (IsSpecial(mat, i, j, m, n))
 435                {
 436                    result++;
 437                }
 1838            }
 639        }
 40
 241        return result;
 242    }
 43
 44    private static bool IsSpecial(int[][] mat, int i, int j, int m, int n)
 1845    {
 1846        if (mat[i][j] != 1)
 1247        {
 1248            return false;
 49        }
 50
 4851        for (var c = 0; c < n; c++)
 1852        {
 1853            if (c == j)
 654            {
 655                continue;
 56            }
 57
 1258            if (mat[i][c] == 1)
 059            {
 060                return false;
 61            }
 1262        }
 63
 4064        for (var r = 0; r < m; r++)
 1665        {
 1666            if (r == i)
 567            {
 568                continue;
 69            }
 70
 1171            if (mat[r][j] == 1)
 272            {
 273                return false;
 74            }
 975        }
 76
 477        return true;
 1878    }
 79}