forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
31 lines (28 loc) · 720 Bytes
/
solution.cpp
File metadata and controls
31 lines (28 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public:
int lexicographic(vector<string>& A, vector<int> &col){
for (int i=0; i<A.size()-1; i++){
for(auto &j:col){
if (A[i][j] < A[i+1][j])
break;
if (A[i][j] > A[i+1][j])
return false;
}
}
return true;
}
int minDeletionSize(vector<string>& A) {
int l = A.size();
int w = A[0].size();
vector<int> col;
int res=0;
for(int i=0;i<w;i++){
col.push_back(i);
if(!lexicographic(A,col)){
col.pop_back();
res += 1;
}
}
return res;
}
};