| | 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 | |
|
| | 12 | | namespace LeetCode.Algorithms.LargestLocalValuesInMatrix; |
| | 13 | |
|
| | 14 | | /// <inheritdoc /> |
| | 15 | | public class LargestLocalValuesInMatrixBruteForce : ILargestLocalValuesInMatrix |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// Time complexity - O(n^2) |
| | 19 | | /// Space complexity - O(n^2) |
| | 20 | | /// </summary> |
| | 21 | | /// <param name="grid"></param> |
| | 22 | | /// <returns></returns> |
| | 23 | | public int[][] LargestLocal(int[][] grid) |
| 2 | 24 | | { |
| 2 | 25 | | var result = new int[grid.Length - 2][]; |
| | 26 | |
|
| 14 | 27 | | for (var i = 0; i < grid.Length - 2; i++) |
| 5 | 28 | | { |
| 5 | 29 | | result[i] = new int[grid.Length - 2]; |
| | 30 | |
|
| 36 | 31 | | for (var j = 0; j < grid.Length - 2; j++) |
| 13 | 32 | | { |
| 104 | 33 | | for (var k = 0; k < 3; k++) |
| 39 | 34 | | { |
| 312 | 35 | | for (var l = 0; l < 3; l++) |
| 117 | 36 | | { |
| 117 | 37 | | result[i][j] = Math.Max(result[i][j], grid[i + k][j + l]); |
| 117 | 38 | | } |
| 39 | 39 | | } |
| 13 | 40 | | } |
| 5 | 41 | | } |
| | 42 | |
|
| 2 | 43 | | return result; |
| 2 | 44 | | } |
| | 45 | | } |