题目
代码部分一(26ms 66.80%)
class Solution {
public int minDeletionSize(String[] A) {
int len = A[0].length();
if(len < 2) return 0;
int res = 0;
int k = A.length;
char[][] ch = new char[k][len];
for(int i = 0; i < k; i++){
ch[i] = A[i].toCharArray();
}
for(int i = 0; i < len; i++){
for(int j = 0; j < k - 1; j++){
if(ch[j][i] > ch[j+1][i]){
res++;
break;
}
}
}
return res;
}
}
代码部分二(14ms 99.26%)
class Solution {
public int minDeletionSize(String[] A) {
int len = A[0].length();
if(len < 2) return 0;
int res = 0;
int k = A.length;
char[][] ch = new char[k][len];
for(int i = 0; i < k; i++){
ch[i] = A[i].toCharArray();
}
for(int i = 0; i < len; i++){
for(int j = 0; j < k - 1; j++){
if(ch[j][i] > ch[j+1][i]){
res++;
break;
}
}
}
return res;
}
}