-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
32 lines (31 loc) · 918 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
namespace CountNegativeNumbersInASortedMatrix
{
class Program
{
static void Main(string[] args)
{
int[][] grid = new int[1][];
grid[0] = new int[] { 16, 16, 16, 16, 15, 14, 14, 13, 13, 13, 12, -9, -9, -10, -10, -10, -10, -11, -11, -11 };
Console.WriteLine(CountNegatives(grid));
}
static int CountNegatives(int[][] grid)
{
int count = 0;
int cLimit = grid[0].Length;
for (int i = 0; i < grid.Length; i++)
{
for (int j = 0; j < cLimit; j++)
{
if (grid[i][j] < 0)
{
count += (cLimit - j) * (grid.Length - i);
cLimit = j;
break;
}
}
}
return count;
}
}
}