Skip to content

Commit 1329bd7

Browse files
committed
Time: 98 ms (47.41%), Space: 12.2 MB (30.23%) - LeetHub
1 parent 315ff12 commit 1329bd7

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
class Solution {
22
public:
33
int minDeletionSize(vector<string>& strs) {
4-
5-
int n = strs.size();
6-
int m = strs[0].size();
7-
int ans = 0;
84

9-
for(int i = 0;i<m; ++i)
5+
int ans = 0;
6+
for(int col = 0; col < strs[0].size(); ++col)
107
{
11-
string str;
12-
for(int j = 0; j <n; ++j)
8+
for(int row = 1; row < strs.size(); ++row)
139
{
14-
str += strs[j][i];
10+
if(strs[row-1][col] > strs[row][col])
11+
{
12+
++ans;
13+
break;
14+
}
1515
}
16-
17-
string sortedStr = str;
18-
sort(sortedStr.begin(),sortedStr.end());
19-
20-
if(str != sortedStr)
21-
++ans;
2216
}
23-
2417
return ans;
2518
}
2619
};

0 commit comments

Comments
 (0)