Skip to content

Commit 7baceea

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

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,49 @@ cae</pre>
8989

9090
```
9191

92+
### **C++**
93+
94+
```cpp
95+
class Solution {
96+
public:
97+
int minDeletionSize(vector<string>& strs) {
98+
int n = strs.size();
99+
int m = strs[0].size();
100+
int res = 0;
101+
for (int i = 0; i < m; ++i) {
102+
for (int j = 0; j < n - 1; ++j) {
103+
if (strs[j][i] > strs[j + 1][i]) {
104+
res++;
105+
break;
106+
}
107+
}
108+
}
109+
return res;
110+
}
111+
};
112+
```
113+
114+
### **Rust**
115+
116+
```rust
117+
impl Solution {
118+
pub fn min_deletion_size(strs: Vec<String>) -> i32 {
119+
let n = strs.len();
120+
let m = strs[0].len();
121+
let mut res = 0;
122+
for i in 0..m {
123+
for j in 1..n {
124+
if strs[j - 1].as_bytes()[i] > strs[j].as_bytes()[i] {
125+
res += 1;
126+
break;
127+
}
128+
}
129+
}
130+
res
131+
}
132+
}
133+
```
134+
92135
### **...**
93136

94137
```

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,49 @@ All 3 columns are not sorted, so you will delete all 3.
8080

8181
```
8282

83+
### **C++**
84+
85+
```cpp
86+
class Solution {
87+
public:
88+
int minDeletionSize(vector<string>& strs) {
89+
int n = strs.size();
90+
int m = strs[0].size();
91+
int res = 0;
92+
for (int i = 0; i < m; ++i) {
93+
for (int j = 0; j < n - 1; ++j) {
94+
if (strs[j][i] > strs[j + 1][i]) {
95+
res++;
96+
break;
97+
}
98+
}
99+
}
100+
return res;
101+
}
102+
};
103+
```
104+
105+
### **Rust**
106+
107+
```rust
108+
impl Solution {
109+
pub fn min_deletion_size(strs: Vec<String>) -> i32 {
110+
let n = strs.len();
111+
let m = strs[0].len();
112+
let mut res = 0;
113+
for i in 0..m {
114+
for j in 1..n {
115+
if strs[j - 1].as_bytes()[i] > strs[j].as_bytes()[i] {
116+
res += 1;
117+
break;
118+
}
119+
}
120+
}
121+
res
122+
}
123+
}
124+
```
125+
83126
### **...**
84127

85128
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int minDeletionSize(vector<string>& strs) {
4+
int n = strs.size();
5+
int m = strs[0].size();
6+
int res = 0;
7+
for (int i = 0; i < m; ++i) {
8+
for (int j = 0; j < n - 1; ++j) {
9+
if (strs[j][i] > strs[j + 1][i]) {
10+
res++;
11+
break;
12+
}
13+
}
14+
}
15+
return res;
16+
}
17+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
impl Solution {
2+
pub fn min_deletion_size(strs: Vec<String>) -> i32 {
3+
let n = strs.len();
4+
let m = strs[0].len();
5+
let mut res = 0;
6+
for i in 0..m {
7+
for j in 1..n {
8+
if strs[j - 1].as_bytes()[i] > strs[j].as_bytes()[i] {
9+
res += 1;
10+
break;
11+
}
12+
}
13+
}
14+
res
15+
}
16+
}

0 commit comments

Comments
 (0)