We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 315ff12 commit 1329bd7Copy full SHA for 1329bd7
0944-delete-columns-to-make-sorted/0944-delete-columns-to-make-sorted.cpp
@@ -1,26 +1,19 @@
1
class Solution {
2
public:
3
int minDeletionSize(vector<string>& strs) {
4
-
5
- int n = strs.size();
6
- int m = strs[0].size();
7
- int ans = 0;
8
9
- for(int i = 0;i<m; ++i)
+ int ans = 0;
+ for(int col = 0; col < strs[0].size(); ++col)
10
{
11
- string str;
12
- for(int j = 0; j <n; ++j)
+ for(int row = 1; row < strs.size(); ++row)
13
14
- str += strs[j][i];
+ if(strs[row-1][col] > strs[row][col])
+ {
+ ++ans;
+ break;
+ }
15
}
16
17
- string sortedStr = str;
18
- sort(sortedStr.begin(),sortedStr.end());
19
20
- if(str != sortedStr)
21
- ++ans;
22
23
24
return ans;
25
26
};
0 commit comments