< Summary

Information
Class: LeetCode.Algorithms.SetMatrixZeroes.SetMatrixZeroesInPlace
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SetMatrixZeroes\SetMatrixZeroesInPlace.cs
Line coverage
100%
Covered lines: 47
Uncovered lines: 0
Coverable lines: 47
Total lines: 78
Line coverage: 100%
Branch coverage
100%
Covered branches: 26
Total branches: 26
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SetZeroes(...)100%2626100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SetMatrixZeroes\SetMatrixZeroesInPlace.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.SetMatrixZeroes;
 13
 14/// <inheritdoc />
 15public class SetMatrixZeroesInPlace : ISetMatrixZeroes
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m * n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="matrix"></param>
 22    public void SetZeroes(int[][] matrix)
 223    {
 224        var firstRowZero = false;
 225        var firstColZero = false;
 26
 1627        for (var i = 0; i < matrix.Length; i++)
 628        {
 5429            for (var j = 0; j < matrix[i].Length; j++)
 2130            {
 2131                if (matrix[i][j] != 0)
 1832                {
 1833                    continue;
 34                }
 35
 336                if (i == 0)
 237                {
 238                    firstRowZero = true;
 239                }
 40
 341                if (j == 0)
 142                {
 143                    firstColZero = true;
 144                }
 45
 346                matrix[i][0] = 0;
 347                matrix[0][j] = 0;
 348            }
 649        }
 50
 1251        for (var i = 1; i < matrix.Length; i++)
 452        {
 2853            for (var j = 1; j < matrix[i].Length; j++)
 1054            {
 1055                if (matrix[i][0] == 0 || matrix[0][j] == 0)
 556                {
 557                    matrix[i][j] = 0;
 558                }
 1059            }
 460        }
 61
 262        if (firstColZero)
 163        {
 964            foreach (var row in matrix)
 365            {
 366                row[0] = 0;
 367            }
 168        }
 69
 270        if (firstRowZero)
 171        {
 1072            for (var j = 0; j < matrix[0].Length; j++)
 473            {
 474                matrix[0][j] = 0;
 475            }
 176        }
 277    }
 78}

Methods/Properties

SetZeroes(System.Int32[][])