< Summary

Information
Class: LeetCode.Algorithms.ValidSudoku.ValidSudokuBoolTables
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ValidSudoku\ValidSudokuBoolTables.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 62
Line coverage: 100%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsValidSudoku(...)83.33%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ValidSudoku\ValidSudokuBoolTables.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.ValidSudoku;
 13
 14/// <inheritdoc />
 15public class ValidSudokuBoolTables : ValidSudokuBase
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n^2)
 19    ///     Space complexity - O(n^2)
 20    /// </summary>
 21    /// <param name="board"></param>
 22    /// <returns></returns>
 23    public override bool IsValidSudoku(char[][] board)
 324    {
 325        Span<bool> rows = stackalloc bool[N * N];
 326        Span<bool> columns = stackalloc bool[N * N];
 327        Span<bool> boxes = stackalloc bool[N * N];
 28
 3229        for (var rowIndex = 0; rowIndex < N; rowIndex++)
 1530        {
 1531            var row = board[rowIndex];
 32
 27833            for (var columnIndex = 0; columnIndex < N; columnIndex++)
 12634            {
 12635                int cell = row[columnIndex];
 36
 12637                if (cell == EmptyCell)
 8238                {
 8239                    continue;
 40                }
 41
 4442                var cellIndex = GetCellIndex(cell);
 4443                var boxIndex = GetBoxIndex(rowIndex, columnIndex);
 44
 4445                var rowSlot = (rowIndex * N) + cellIndex;
 4446                var columnSlot = (columnIndex * N) + cellIndex;
 4447                var boxSlot = (boxIndex * N) + cellIndex;
 48
 4449                if (rows[rowSlot] || columns[columnSlot] || boxes[boxSlot])
 250                {
 251                    return false;
 52                }
 53
 4254                rows[rowSlot] = true;
 4255                columns[columnSlot] = true;
 4256                boxes[boxSlot] = true;
 4257            }
 1358        }
 59
 160        return true;
 361    }
 62}

Methods/Properties

IsValidSudoku(System.Char[][])