Skip to content

Commit 65291b4

Browse files
Add files via upload
1 parent eaebde6 commit 65291b4

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Runtime: 60 ms, faster than 68.94% of C++ online submissions for Delete Columns to Make Sorted.
2+
// Memory Usage: 13.1 MB, less than 17.60% of C++ online submissions for Delete Columns to Make Sorted.
3+
4+
class Solution
5+
{
6+
public:
7+
int minDeletionSize(vector<string>& A)
8+
{
9+
// 边界条件处理
10+
if (A.size() == 0) return 0;
11+
12+
int res = 0;
13+
14+
for (int j = 0; j < A[0].size(); j++)
15+
{
16+
for (int i = 1; i < A.size(); i++)
17+
{
18+
if (A[i][j] < A[i - 1][j])
19+
{
20+
res++;
21+
break;
22+
}
23+
}
24+
}
25+
return res;
26+
}
27+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Runtime: 236 ms, faster than 13.62% of Python3 online submissions for Delete Columns to Make Sorted.
2+
# Memory Usage: 14.5 MB, less than 5.02% of Python3 online submissions for Delete Columns to Make Sorted.
3+
4+
class Solution:
5+
def minDeletionSize(self, A: List[str]) -> int:
6+
7+
if not A:
8+
return 0
9+
10+
res = 0
11+
12+
for j in range(len(A[0])):
13+
for i in range(1, len(A)):
14+
if ord(A[i][j]) < ord(A[i - 1][j]):
15+
res += 1
16+
break
17+
18+
return res

0 commit comments

Comments
 (0)