• Leetcode-955 Delete Columns to Make Sorted II(删列造序 ||)


     1 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
     2 
     3 
     4 string ooder = "abcdefghijklmnopqrstuvwxyz";
     5 bool cmp(const string &a,const string &b)
     6 {
     7     for(int i = 0; i < min(a.size(),b.size()); i ++)
     8     {
     9         if(a[i]!=b[i])
    10         {
    11             for(int j = 0; j < ooder.size(); j ++)
    12             {
    13                 if(ooder[j]==a[i])
    14                     return 1;
    15                 else if(ooder[j]==b[i])
    16                     return 0;
    17             }
    18         }
    19     }
    20     return true;
    21 }
    22 
    23 bool ok(vector<string> A)
    24 {
    25     for(int i = 0; i < A.size()-1; i++)
    26     {
    27         if(!cmp(A[i],A[i+1]))
    28             return false;    
    29     }
    30     return true;
    31 }
    32 
    33 class Solution
    34 {
    35     public:
    36         int minDeletionSize(vector<string>& A)
    37         {
    38             if(ok(A))
    39                 return 0;
    40             int rnt = 0;
    41             int end = 0;
    42             int flag = 0;
    43             vector<string> tmp = A;
    44             while(!tmp[0].empty()&&!ok(tmp))
    45             {
    46                 for(int i = 0; i < tmp.size()-1; i ++)
    47                 {
    48                     if(tmp[i][end]>tmp[i+1][end])
    49                     {
    50                         if(end!=0&&tmp[i][end-1]<tmp[i+1][end-1])
    51                             continue;
    52                         flag = 1;
    53                         break;
    54                     }
    55                 }
    56                 if(flag)
    57                 {
    58                     _for(k,0,tmp.size())
    59                         tmp[k].erase(end, 1);
    60                     rnt ++;
    61                     end --;
    62                 }
    63                 flag = 0;
    64                 end ++;
    65             }
    66             return rnt;
    67         }
    68 };
  • 相关阅读:
    HTML5语义化标签
    VueRouter配置2index.js文件
    Vue中的App组件
    vuerouter具体配置1
    SGML、HTML、XML、XHTML、HTML5
    Vue中,props配置项
    Vue单文件组件的使用
    html5有哪些新特性,移除了哪些元素
    VueRouter具体流程
    html单选与多选框
  • 原文地址:https://www.cnblogs.com/Asurudo/p/10090765.html
Copyright © 2020-2023  润新知