< Summary

Information
Class: LeetCode.Algorithms.SpiralMatrix.SpiralMatrixSimulation
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SpiralMatrix\SpiralMatrixSimulation.cs
Line coverage
100%
Covered lines: 44
Uncovered lines: 0
Coverable lines: 44
Total lines: 83
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SpiralOrder(...)100%1616100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SpiralMatrix\SpiralMatrixSimulation.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.SpiralMatrix;
 13
 14/// <inheritdoc />
 15public class SpiralMatrixSimulation : ISpiralMatrix
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n * m)
 19    ///     Space complexity - O(n * m)
 20    /// </summary>
 21    /// <param name="matrix"></param>
 22    /// <returns></returns>
 23    public IList<int> SpiralOrder(int[][] matrix)
 224    {
 225        var rows = matrix.Length;
 226        var columns = matrix[0].Length;
 27
 228        var spiralMatrix = new int[rows * columns];
 229        var spiralMatrixIndex = 0;
 30
 231        var left = 0;
 232        var top = 0;
 233        var right = columns - 1;
 234        var bottom = rows - 1;
 35
 636        while (top <= bottom && left <= right)
 437        {
 2838            for (var j = left; j <= right; j++)
 1039            {
 1040                spiralMatrix[spiralMatrixIndex] = matrix[top][j];
 41
 1042                spiralMatrixIndex++;
 1043            }
 44
 445            top++;
 46
 1647            for (var i = top; i <= bottom; i++)
 448            {
 449                spiralMatrix[spiralMatrixIndex] = matrix[i][right];
 50
 451                spiralMatrixIndex++;
 452            }
 53
 454            right--;
 55
 456            if (top <= bottom)
 257            {
 1458                for (var j = right; j >= left; j--)
 559                {
 560                    spiralMatrix[spiralMatrixIndex] = matrix[bottom][j];
 61
 562                    spiralMatrixIndex++;
 563                }
 64
 265                bottom--;
 266            }
 67
 468            if (left <= right)
 369            {
 1070                for (var i = bottom; i >= top; i--)
 271                {
 272                    spiralMatrix[spiralMatrixIndex] = matrix[i][left];
 73
 274                    spiralMatrixIndex++;
 275                }
 76
 377                left++;
 378            }
 479        }
 80
 281        return spiralMatrix;
 282    }
 83}

Methods/Properties

SpiralOrder(System.Int32[][])