< Summary

Information
Class: LeetCode.Algorithms.FindWinnerOnTicTacToeGame.FindWinnerOnTicTacToeGameSimulation
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindWinnerOnTicTacToeGame\FindWinnerOnTicTacToeGameSimulation.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 63
Line coverage: 100%
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
Tictactoe(...)95%2020100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindWinnerOnTicTacToeGame\FindWinnerOnTicTacToeGameSimulation.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.FindWinnerOnTicTacToeGame;
 13
 14/// <inheritdoc />
 15public class FindWinnerOnTicTacToeGameSimulation : IFindWinnerOnTicTacToeGame
 16{
 17    private const int GridSize = 3;
 18
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(1)
 22    /// </summary>
 23    /// <param name="moves"></param>
 24    /// <returns></returns>
 25    public string Tictactoe(int[][] moves)
 326    {
 327        var rowSum = new int[GridSize];
 328        var columnSum = new int[GridSize];
 329        var leftDiagonalSum = 0;
 330        var rightDiagonalSum = 0;
 31
 4232        for (var i = 0; i < moves.Length; i++)
 2033        {
 2034            var value = i % 2 == 0 ? 1 : -1;
 35
 2036            var row = moves[i][0];
 2037            var col = moves[i][1];
 38
 2039            rowSum[row] += value;
 2040            columnSum[col] += value;
 41
 2042            if (row == col)
 843            {
 844                leftDiagonalSum += value;
 845            }
 46
 2047            if (row + col == GridSize - 1)
 848            {
 849                rightDiagonalSum += value;
 850            }
 51
 2052            if (Math.Abs(rowSum[row]) == GridSize ||
 2053                Math.Abs(columnSum[col]) == GridSize ||
 2054                Math.Abs(leftDiagonalSum) == GridSize ||
 2055                Math.Abs(rightDiagonalSum) == GridSize)
 256            {
 257                return value == 1 ? "A" : "B";
 58            }
 1859        }
 60
 161        return moves.Length == GridSize * GridSize ? "Draw" : "Pending";
 362    }
 63}

Methods/Properties

Tictactoe(System.Int32[][])