-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSolution955.java
More file actions
32 lines (29 loc) · 797 Bytes
/
Solution955.java
File metadata and controls
32 lines (29 loc) · 797 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
package algorithm.leetcode;
/**
* @author: mayuan
* @desc: 删列造序 II
* @date: 2019/02/12
*/
public class Solution955 {
public int minDeletionSize(String[] A) {
int ans = 0, n = A.length, m = A[0].length(), i, j;
boolean[] sorted = new boolean[n - 1];
for (j = 0; j < m; ++j) {
for (i = 0; i < n - 1; ++i) {
if (!sorted[i] && A[i].charAt(j) > A[i + 1].charAt(j)) {
++ans;
break;
}
}
if (i < n - 1) {
continue;
}
for (i = 0; i < n - 1; ++i) {
if (A[i].charAt(j) < A[i + 1].charAt(j)) {
sorted[i] = true;
}
}
}
return ans;
}
}