Leetcode-944 Delete Columns to Make Sorted(删除列以使之有序)

 1 class Solution
 2 {
 3     public:
 4         bool order(string A)
 5         {
 6             for(int i = 0; i < A.size()-1; i ++)
 7             {
 8                 if(A[i]>A[i+1])
 9                 {
10                     return false;
11                 }
12             }
13             return true;
14         }
15         int minDeletionSize(vector<string>& A)
16         {
17             int indexMax = A[0].size();
18 
19             int result = 0;
20             for(int i = 0; i < indexMax; i ++)
21             {
22                 string tmp;
23                 for(int j = 0; j < A.size(); j ++)
24                 {
25                     tmp += A[j][i];
26                 }
27                 if(!order(tmp))
28                     result ++;
29                 tmp.clear();
30             }
31             return result;
32         }
33 };

 

posted @ 2018-11-18 12:48  Asurudo  阅读(342)  评论(0编辑  收藏  举报