- 题目描述
- 思路
- 模拟
- Python实现
- Java实现
题目描述
删列造序
思路 模拟
根据题意模拟即可。对于第j列,只需要判断所有相邻字符判断strs[i-1][j] <= strs[i][j]即可。
Python实现class Solution:
def minDeletionSize(self, strs: List[str]) -> int:
return sum(list(column) != sorted(column) for column in zip(*strs))
Java实现
class Solution {
public int minDeletionSize(String[] strs) {
int n = strs.length, m = strs[0].length();
int ans = 0;
for (int j = 0; j < m; ++j) {
for (int i = 1; i < n; ++i) {
if (strs[i-1].charAt(j) > strs[i].charAt(j)) {
ans++;
break;
}
}
}
return ans;
}
}



