-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
35 lines (35 loc) · 889 Bytes
/
Solution.cs
File metadata and controls
35 lines (35 loc) · 889 Bytes
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
33
34
35
public class Solution
{
public int MinDeletionSize(string[] strs)
{
int n = strs.Length, m = strs[0].Length;
int ans = 0;
bool[] cuts = new bool[n];
for (int col = 0; col < m; col++)
{
bool isCorrect = true;
for (int row = 1; row < n; row++)
{
if (cuts[row]) continue;
if (strs[row][col] < strs[row - 1][col])
{
isCorrect = false;
break;
}
}
if (!isCorrect)
{
ans++;
continue;
}
for (int row = 1; row < n; row++)
{
if (strs[row][col] > strs[row - 1][col])
{
cuts[row] = true;
}
}
}
return ans;
}
}