解题思路:
(1)取出字符串数组s中的每一列组成新的字符串数组
(2)遍历新的字符串数组的每一行,比较当前行的相邻字符的大小,如果出现前一个字符比后一个字符搭的情况,说明当前列要删除,计数器加1
class Solution {
public int minDeletionSize(String[] A) {
int rows=A.length;
int cols=A[0].length();
String[] arrays=new String[cols];
for(int i=0;i<cols;++i){
String temp="";
for(int j=0;j<rows;++j){
temp+=A[j].substring(i,i+1);
}
arrays[i]=temp;
}
int cnt=0;
for(int i=0;i<cols;++i){
String temp=arrays[i];
for(int j=0;j<rows-1;++j){
if(temp.charAt(j)>temp.charAt(j+1)){
cnt++;
break;
}
}
}
return cnt;
}
}
来源:CSDN
作者:我就是个渴望成长的小菜鸡
链接:https://blog.csdn.net/junjunjiao0911/article/details/103856622