2022-5-12 每日一题-leetcode

题目链接:https://leetcode.cn/problems/delete-columns-to-make-sorted/

个人题解:直接遍历即可,暴力两重循环

代码:

class Solution {
public:
    int minDeletionSize(vector<string>& strs) {
        int n=strs[0].size(),m=strs.size();

        int res=0;
        for(int j=0;j<n;j++){
            for(int i=0;i<m-1;i++){
                if(strs[i][j]>strs[i+1][j]){
                    res++;
                    break;
                }
            }
        }
        return res;
    }
};

运行截图:

image

posted @ 2022-05-12 08:28  黑VS白-清墨  阅读(27)  评论(0)    收藏  举报