| | | 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.CountNegativeNumbersInSortedMatrix; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public sealed class CountNegativeNumbersInSortedMatrixBruteForceBottomRight : ICountNegativeNumbersInSortedMatrix |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Time complexity - O(n * m) |
| | | 19 | | /// Space complexity - O(1) |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="grid"></param> |
| | | 22 | | /// <returns></returns> |
| | | 23 | | public int CountNegatives(int[][] grid) |
| | 2 | 24 | | { |
| | 2 | 25 | | var count = 0; |
| | | 26 | | |
| | 2 | 27 | | var m = grid.Length; |
| | 2 | 28 | | var n = grid[0].Length; |
| | | 29 | | |
| | 16 | 30 | | for (var i = m - 1; i >= 0; i--) |
| | 6 | 31 | | { |
| | 28 | 32 | | for (var j = n - 1; j >= 0; j--) |
| | 13 | 33 | | { |
| | 13 | 34 | | if (grid[i][j] >= 0) |
| | 5 | 35 | | { |
| | 5 | 36 | | break; |
| | | 37 | | } |
| | | 38 | | |
| | 8 | 39 | | count++; |
| | 8 | 40 | | } |
| | 6 | 41 | | } |
| | | 42 | | |
| | 2 | 43 | | return count; |
| | 2 | 44 | | } |
| | | 45 | | } |