955. 删列造序 II
题目链接:955. 删列造序 II
代码如下:
cpp
class Solution {
public:
int minDeletionSize(vector<string>& strs) {
int res = 0;
int n = strs.size(), m = strs[0].size();
vector<string> a(n); //最终得到的字符串数量
for (int j = 0;j < m;j++) {
bool del = false;
for (int i = 0;i < n - 1;i++) {
if (a[i] + strs[i][j] > a[i + 1] + strs[i + 1][j]) {
res++;
del = true;
break;
}
}
if (!del) {
for (int i = 0;i < n;i++) {
a[i] += strs[i][j];
}
}
}
return res;
}
};