-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path960.cpp
More file actions
25 lines (25 loc) · 714 Bytes
/
960.cpp
File metadata and controls
25 lines (25 loc) · 714 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
class Solution {
public:
int minDeletionSize(vector<string>& strs) {
int n = strs.size();
int m = strs[0].size();
vector<int> dp(m, 1);
int invRes = 1;
for (int i = 1; i < m; ++i) {
for (int j = 0; j < i; ++j) {
bool okay = true;
for (int k = 0; k < n; ++k) {
if (strs[k][j] > strs[k][i]) {
okay = false;
break;
}
}
if (okay) {
dp[i] = max(dp[i], dp[j] + 1);
invRes = max(invRes, dp[i]);
}
}
}
return m - invRes;
}
};