Skip to content

Commit 5e1bd3e

Browse files
committed
update: 添加问题“955.删列造序II”的代码和题解 (#1271)
955: AC.cpp - AC,100.00,81.82% (#1270) + word(en) 一遍过喽 Signed-off-by: LetMeFly666 <[email protected]>
1 parent b23dcc4 commit 5e1bd3e

20 files changed

+243
-90
lines changed

.commitmsg

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
944: AC.cpp+java+py+go+rust(#1268) + word(en) + 1problem1day
1+
955: AC.cpp - AC,100.00,81.82% (#1270) + word(en)
22

3-
cpp - WA
4-
cpp - AC,27.82%,45.86%
5-
py(oneline) - CE
6-
py(oneline) - AC,11.04%,70.13%
7-
go - AC,100.00%,38.89%
8-
java - AC,84.34%,6.03%
9-
rust - CE
10-
rust - AC,33.33%,83.33%
3+
一遍过喽

.github/workflows/1problem1day-autoGenIssueEveryday.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545
--body "By Github Actions | [$id.$title](https://leetcode.cn/problems/$slug/) | $date" \
4646
--label 题解 \
4747
--assignee LetMeFly666 \
48-
--repo LetMeFly666/LeetCode-test
48+
--repo "${{ github.repository }}"

.github/workflows/1problem1day-closeAndSetDate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
closed_at="${{ github.event.issue.closed_at }}"
2626
date_cn=$(date -d "$closed_at +8 hours" +%F)
2727
28-
echo "Query project item_id via Issue.projectItems..."
28+
echo "Query project item_id via Issue.projectItems..."
2929
item_id=$(gh api graphql -f query='
3030
query($issue:ID!) {
3131
node(id:$issue) {

Codes/0944-delete-columns-to-make-sorted_20251220.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
* @Author: LetMeFly
33
* @Date: 2025-12-20 22:44:28
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2025-12-20 22:46:33
5+
* @LastEditTime: 2025-12-20 22:48:32
66
*/
77
#if defined(_WIN32) || defined(__APPLE__)
88
#include "_[1,2]toVector.h"
99
#endif
1010

11-
// THIS CAN NOT AC
1211
class Solution {
1312
public:
1413
int minDeletionSize(vector<string>& strs) {
1514
int n = strs.size(), m = strs[0].size();
1615
int ans = 0;
1716
for (int j = 0; j < m; j++) {
1817
for (int i = 1; i < n; i++) {
19-
if (strs[i][j] <= strs[i - 1][j]) {
18+
if (strs[i][j] < strs[i - 1][j]) { // 好吧,相同相邻字符是合法的
2019
ans++;
2120
break;
2221
}

Codes/0944-delete-columns-to-make-sorted_20251220.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
Author: LetMeFly
33
Date: 2025-12-20 22:44:28
44
LastEditors: LetMeFly.xyz
5-
LastEditTime: 2025-12-20 22:52:49
5+
LastEditTime: 2025-12-20 22:55:49
66
'''
77
from typing import List
88

9-
# THIS CAN NOT ACCESS
109
class Solution:
1110
def minDeletionSize(self, strs: List[str]) -> int:
12-
return sum(any(strs[i][j] < strs[i-1][j] for i in range(1, len(strs)) for j in range(len(strs))))
11+
return sum(any(strs[i][j] < strs[i-1][j] for i in range(1, len(strs))) for j in range(len(strs[0])))

Codes/0944-delete-columns-to-make-sorted_20251220.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
* @Author: LetMeFly
33
* @Date: 2025-12-20 22:44:28
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2025-12-20 23:02:29
5+
* @LastEditTime: 2025-12-20 23:02:37
66
*/
7-
// THIS CANNOT ACCESS
87
impl Solution {
98
pub fn min_deletion_size(strs: Vec<String>) -> i32 {
109
let n = strs.len();
1110
let m = strs[0].len();
1211
let mut ans: i32 = 0;
1312
for j in 0..m {
14-
for i in 0..n {
15-
if strs[i][j] < strs[i-1][j] {
13+
for i in 1..n {
14+
if strs[i].chars().nth(j).unwrap() < strs[i-1].chars().nth(j).unwrap() {
1615
ans += 1;
1716
break;
1817
}

Codes/0944-delete-columns-to-make-sorted_20251220_AC.cpp

Lines changed: 0 additions & 26 deletions
This file was deleted.

Codes/0944-delete-columns-to-make-sorted_20251220_AC.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

Codes/0944-delete-columns-to-make-sorted_20251220_AC.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-21 20:40:47
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-21 20:46:33
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int minDeletionSize(vector<string>& strs) {
14+
int ans = 0;
15+
int n = strs.size(), m = strs[0].size();
16+
int totalSkip = 1; // 第一行不用校验
17+
vector<bool> canSkip(n);
18+
for (int j = 0; j < m; j++) {
19+
bool can = true;
20+
for (int i = 1; i < n; i++) {
21+
if (canSkip[i]) {
22+
continue;
23+
}
24+
if (strs[i][j] < strs[i-1][j]) {
25+
can = false;
26+
break;
27+
}
28+
}
29+
if (can) {
30+
for (int i = 1; i < n; i++) {
31+
if (strs[i][j] != strs[i-1][j] && !canSkip[i]) {
32+
canSkip[i] = true;
33+
totalSkip++;
34+
if (totalSkip == n) {
35+
return ans;
36+
}
37+
}
38+
}
39+
} else {
40+
ans++;
41+
}
42+
}
43+
return ans;
44+
}
45+
};

0 commit comments

Comments
 (0)