-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path955.cpp
More file actions
34 lines (30 loc) · 868 Bytes
/
955.cpp
File metadata and controls
34 lines (30 loc) · 868 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
class Solution {
public:
int minDeletionSize(vector<string>& strs) {
int n = strs.size();
int m = strs[0].size();
vector<bool> isSored(n - 1, false);
int res = 0;
int cnt = 0;
for (int j = 0; j < m; ++j) {
bool isEnd = false;
for (int i = 0; i < n - 1; ++i) {
if (!isSored[i] && strs[i][j] > strs[i + 1][j]) {
res++;
break;
}
if (i == n - 2) isEnd = true;
}
if (isEnd) {
for (int i = 0; i < n - 1; ++i) {
if (strs[i][j] < strs[i + 1][j]) {
isSored[i] = true;
cnt++;
}
}
}
if (cnt == n) break;
}
return res;
}
};