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

Posted Asurudo Jyo の 倉 庫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 };

 

以上是关于Leetcode-955 Delete Columns to Make Sorted II(删列造序 ||)的主要内容,如果未能解决你的问题,请参考以下文章

哪个更快/最好? SELECT * 或 SELECT column1、colum2、column3 等

查询结束概念

mysql 学习

Vue+EleMentUI实现el-table-colum表格select下拉框可编辑

1140 In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated colum

[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum