| | | 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 | | |
| | | 12 | | namespace LeetCode.Algorithms.CheckIfTwoChessboardSquaresHaveTheSameColor; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public sealed class CheckIfTwoChessboardSquaresHaveTheSameColorLookup : CheckIfTwoChessboardSquaresHaveTheSameColorBase |
| | | 16 | | { |
| | | 17 | | private const int BoardSize = 8; |
| | 1 | 18 | | private static readonly bool[,] CellsLookup = CreateCellsLookup(); |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Time complexity - O(1) |
| | | 22 | | /// Space complexity - O(1) |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="coordinate1"></param> |
| | | 25 | | /// <param name="coordinate2"></param> |
| | | 26 | | /// <returns></returns> |
| | | 27 | | public override bool CheckTwoChessboards(string coordinate1, string coordinate2) |
| | 13 | 28 | | { |
| | 13 | 29 | | var (x1, y1) = ParseCoordinate(coordinate1); |
| | 13 | 30 | | var (x2, y2) = ParseCoordinate(coordinate2); |
| | | 31 | | |
| | 13 | 32 | | return CellsLookup[x1, y1] == CellsLookup[x2, y2]; |
| | 13 | 33 | | } |
| | | 34 | | |
| | | 35 | | private static bool[,] CreateCellsLookup() |
| | 1 | 36 | | { |
| | 1 | 37 | | var cells = new bool[BoardSize, BoardSize]; |
| | | 38 | | |
| | 18 | 39 | | for (var x = 0; x < BoardSize; x++) |
| | 8 | 40 | | { |
| | 144 | 41 | | for (var y = 0; y < BoardSize; y++) |
| | 64 | 42 | | { |
| | 64 | 43 | | cells[x, y] = GetColor(x, y); |
| | 64 | 44 | | } |
| | 8 | 45 | | } |
| | | 46 | | |
| | 1 | 47 | | return cells; |
| | 1 | 48 | | } |
| | | 49 | | } |