Skip to content

Commit c9f0181

Browse files
committed
feat: add solutions to lc problem: No.0944
No.0944.Delete Columns to Make Sorted
1 parent 7baceea commit c9f0181

File tree

5 files changed

+122
-14
lines changed

5 files changed

+122
-14
lines changed

solution/0900-0999/0944.Delete Columns to Make Sorted/README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,38 @@ cae</pre>
7878
<!-- 这里可写当前语言的特殊实现逻辑 -->
7979

8080
```python
81-
81+
class Solution:
82+
def minDeletionSize(self, strs: List[str]) -> int:
83+
m, n = len(strs[0]), len(strs)
84+
ans = 0
85+
for j in range(m):
86+
for i in range(1, n):
87+
if strs[i][j] < strs[i - 1][j]:
88+
ans += 1
89+
break
90+
return ans
8291
```
8392

8493
### **Java**
8594

8695
<!-- 这里可写当前语言的特殊实现逻辑 -->
8796

8897
```java
89-
98+
class Solution {
99+
public int minDeletionSize(String[] strs) {
100+
int m = strs[0].length(), n = strs.length;
101+
int ans = 0;
102+
for (int j = 0; j < m; ++j) {
103+
for (int i = 1; i < n; ++i) {
104+
if (strs[i].charAt(j) < strs[i - 1].charAt(j)) {
105+
++ans;
106+
break;
107+
}
108+
}
109+
}
110+
return ans;
111+
}
112+
}
90113
```
91114

92115
### **C++**
@@ -132,6 +155,24 @@ impl Solution {
132155
}
133156
```
134157

158+
### **Go**
159+
160+
```go
161+
func minDeletionSize(strs []string) int {
162+
m, n := len(strs[0]), len(strs)
163+
ans := 0
164+
for j := 0; j < m; j++ {
165+
for i := 1; i < n; i++ {
166+
if strs[i][j] < strs[i-1][j] {
167+
ans++
168+
break
169+
}
170+
}
171+
}
172+
return ans
173+
}
174+
```
175+
135176
### **...**
136177

137178
```

solution/0900-0999/0944.Delete Columns to Make Sorted/README_EN.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,36 @@ All 3 columns are not sorted, so you will delete all 3.
7171
### **Python3**
7272

7373
```python
74-
74+
class Solution:
75+
def minDeletionSize(self, strs: List[str]) -> int:
76+
m, n = len(strs[0]), len(strs)
77+
ans = 0
78+
for j in range(m):
79+
for i in range(1, n):
80+
if strs[i][j] < strs[i - 1][j]:
81+
ans += 1
82+
break
83+
return ans
7584
```
7685

7786
### **Java**
7887

7988
```java
80-
89+
class Solution {
90+
public int minDeletionSize(String[] strs) {
91+
int m = strs[0].length(), n = strs.length;
92+
int ans = 0;
93+
for (int j = 0; j < m; ++j) {
94+
for (int i = 1; i < n; ++i) {
95+
if (strs[i].charAt(j) < strs[i - 1].charAt(j)) {
96+
++ans;
97+
break;
98+
}
99+
}
100+
}
101+
return ans;
102+
}
103+
}
81104
```
82105

83106
### **C++**
@@ -123,6 +146,24 @@ impl Solution {
123146
}
124147
```
125148

149+
### **Go**
150+
151+
```go
152+
func minDeletionSize(strs []string) int {
153+
m, n := len(strs[0]), len(strs)
154+
ans := 0
155+
for j := 0; j < m; j++ {
156+
for i := 1; i < n; i++ {
157+
if strs[i][j] < strs[i-1][j] {
158+
ans++
159+
break
160+
}
161+
}
162+
}
163+
return ans
164+
}
165+
```
166+
126167
### **...**
127168

128169
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
func minDeletionSize(strs []string) int {
2+
m, n := len(strs[0]), len(strs)
3+
ans := 0
4+
for j := 0; j < m; j++ {
5+
for i := 1; i < n; i++ {
6+
if strs[i][j] < strs[i-1][j] {
7+
ans++
8+
break
9+
}
10+
}
11+
}
12+
return ans
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int minDeletionSize(String[] strs) {
3+
int m = strs[0].length(), n = strs.length;
4+
int ans = 0;
5+
for (int j = 0; j < m; ++j) {
6+
for (int i = 1; i < n; ++i) {
7+
if (strs[i].charAt(j) < strs[i - 1].charAt(j)) {
8+
++ans;
9+
break;
10+
}
11+
}
12+
}
13+
return ans;
14+
}
15+
}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
class Solution:
2-
def minDeletionSize(self, A: 'List[str]') -> 'int':
3-
4-
count = 0
5-
6-
for i in range(len(A[0])):
7-
for j in range(len(A) - 1):
8-
if A[j][i] > A[j + 1][i]:
9-
count += 1
2+
def minDeletionSize(self, strs: List[str]) -> int:
3+
m, n = len(strs[0]), len(strs)
4+
ans = 0
5+
for j in range(m):
6+
for i in range(1, n):
7+
if strs[i][j] < strs[i - 1][j]:
8+
ans += 1
109
break
11-
12-
return count
10+
return ans

0 commit comments

Comments
 (0)