File tree Expand file tree Collapse file tree 5 files changed +122
-14
lines changed
solution/0900-0999/0944.Delete Columns to Make Sorted Expand file tree Collapse file tree 5 files changed +122
-14
lines changed Original file line number Diff line number Diff line change @@ -78,15 +78,38 @@ cae</pre>
78
78
<!-- 这里可写当前语言的特殊实现逻辑 -->
79
79
80
80
``` 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
82
91
```
83
92
84
93
### ** Java**
85
94
86
95
<!-- 这里可写当前语言的特殊实现逻辑 -->
87
96
88
97
``` 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
+ }
90
113
```
91
114
92
115
### ** C++**
@@ -132,6 +155,24 @@ impl Solution {
132
155
}
133
156
```
134
157
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
+
135
176
### ** ...**
136
177
137
178
```
Original file line number Diff line number Diff line change @@ -71,13 +71,36 @@ All 3 columns are not sorted, so you will delete all 3.
71
71
### ** Python3**
72
72
73
73
``` 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
75
84
```
76
85
77
86
### ** Java**
78
87
79
88
``` 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
+ }
81
104
```
82
105
83
106
### ** C++**
@@ -123,6 +146,24 @@ impl Solution {
123
146
}
124
147
```
125
148
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
+
126
167
### ** ...**
127
168
128
169
```
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
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
10
9
break
11
-
12
- return count
10
+ return ans
You can’t perform that action at this time.
0 commit comments