Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit c28516c

Browse files
committed
944 added
1 parent 157cda7 commit c28516c

File tree

5 files changed

+119
-23
lines changed

5 files changed

+119
-23
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"ttca",
100100
"unique",
101101
"username",
102+
"uvwxyz",
102103
"zppedxfumcfsngp"
103104
],
104105
"cSpell.language": "en,en-US"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# [944. Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted/)
2+
3+
We are given an array `A` of `N` lowercase letter strings, all of the same length.
4+
5+
Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices.
6+
7+
For example, if we have an array `A = ["abcdef","uvwxyz"]` and deletion indices `{0, 2, 3}`, then the final array after deletions is `["bef", "vyz"]`, and the remaining columns of A are `["b","v"]`, `["e","y"]`, and `["f","z"]`. (Formally, the c-th column is `[A[0][c], A[1][c], ..., A[A.length-1][c]]`.)
8+
9+
Suppose we chose a set of deletion indices `D` such that after deletions, each remaining column in A is in **non-decreasing** sorted order.
10+
11+
Return the minimum possible value of `D.length`.
12+
13+
Example 1:
14+
15+
```text
16+
Input: ["cba","daf","ghi"]
17+
Output: 1
18+
Explanation:
19+
After choosing D = {1}, each column ["c","d","g"] and ["a","f","i"] are in non-decreasing sorted order.
20+
If we chose D = {}, then a column ["b","a","h"] would not be in non-decreasing sorted order.
21+
```
22+
23+
Example 2:
24+
25+
```text
26+
Input: ["a","b"]
27+
Output: 0
28+
Explanation: D = {}
29+
```
30+
31+
Example 3:
32+
33+
```text
34+
Input: ["zyx","wvu","tsr"]
35+
Output: 3
36+
Explanation: D = {0, 1, 2}
37+
```
38+
39+
Note:
40+
41+
- `1 <= A.length <= 100`
42+
- `1 <= A[i].length <= 1000`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0944
2+
3+
func minDeletionSize(A []string) int {
4+
5+
return 0
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package problem0944
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// tcs is testcase slice
10+
var tcs = []struct {
11+
A []string
12+
ans int
13+
}{
14+
15+
{
16+
[]string{"cba", "daf", "ghi"},
17+
1,
18+
},
19+
20+
{
21+
[]string{"a", "b"},
22+
0,
23+
},
24+
25+
{
26+
[]string{"zyx", "wvu", "tsr"},
27+
3,
28+
},
29+
30+
// 可以有多个 testcase
31+
}
32+
33+
func Test_minDeletionSize(t *testing.T) {
34+
ast := assert.New(t)
35+
36+
for _, tc := range tcs {
37+
ast.Equal(tc.ans, minDeletionSize(tc.A), "输入:%v", tc)
38+
}
39+
}
40+
41+
func Benchmark_minDeletionSize(b *testing.B) {
42+
for i := 0; i < b.N; i++ {
43+
for _, tc := range tcs {
44+
minDeletionSize(tc.A)
45+
}
46+
}
47+
}

leetcode.json

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
3-
"Ranking": 937,
4-
"Updated": "2019-02-27T21:18:31.782351496+08:00",
3+
"Ranking": 932,
4+
"Updated": "2019-02-28T20:45:48.518497191+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 211,
@@ -1129,7 +1129,7 @@
11291129
"ID": 92,
11301130
"Title": "Reverse Linked List II",
11311131
"TitleSlug": "reverse-linked-list-ii",
1132-
"PassRate": "33%",
1132+
"PassRate": "34%",
11331133
"Difficulty": "Medium",
11341134
"IsAccepted": true,
11351135
"IsPaid": false,
@@ -2101,7 +2101,7 @@
21012101
"ID": 173,
21022102
"Title": "Binary Search Tree Iterator",
21032103
"TitleSlug": "binary-search-tree-iterator",
2104-
"PassRate": "46%",
2104+
"PassRate": "47%",
21052105
"Difficulty": "Medium",
21062106
"IsAccepted": false,
21072107
"IsPaid": false,
@@ -3253,7 +3253,7 @@
32533253
"ID": 269,
32543254
"Title": "Alien Dictionary",
32553255
"TitleSlug": "alien-dictionary",
3256-
"PassRate": "29%",
3256+
"PassRate": "30%",
32573257
"Difficulty": "Hard",
32583258
"IsAccepted": false,
32593259
"IsPaid": true,
@@ -4417,7 +4417,7 @@
44174417
"ID": 366,
44184418
"Title": "Find Leaves of Binary Tree",
44194419
"TitleSlug": "find-leaves-of-binary-tree",
4420-
"PassRate": "63%",
4420+
"PassRate": "64%",
44214421
"Difficulty": "Medium",
44224422
"IsAccepted": false,
44234423
"IsPaid": true,
@@ -8161,7 +8161,7 @@
81618161
"ID": 678,
81628162
"Title": "Valid Parenthesis String",
81638163
"TitleSlug": "valid-parenthesis-string",
8164-
"PassRate": "31%",
8164+
"PassRate": "32%",
81658165
"Difficulty": "Medium",
81668166
"IsAccepted": true,
81678167
"IsPaid": false,
@@ -8749,7 +8749,7 @@
87498749
"ID": 727,
87508750
"Title": "Minimum Window Subsequence",
87518751
"TitleSlug": "minimum-window-subsequence",
8752-
"PassRate": "35%",
8752+
"PassRate": "36%",
87538753
"Difficulty": "Hard",
87548754
"IsAccepted": false,
87558755
"IsPaid": true,
@@ -8905,7 +8905,7 @@
89058905
"ID": 740,
89068906
"Title": "Delete and Earn",
89078907
"TitleSlug": "delete-and-earn",
8908-
"PassRate": "44%",
8908+
"PassRate": "45%",
89098909
"Difficulty": "Medium",
89108910
"IsAccepted": true,
89118911
"IsPaid": false,
@@ -9037,7 +9037,7 @@
90379037
"ID": 751,
90389038
"Title": "IP to CIDR",
90399039
"TitleSlug": "ip-to-cidr",
9040-
"PassRate": "57%",
9040+
"PassRate": "58%",
90419041
"Difficulty": "Easy",
90429042
"IsAccepted": false,
90439043
"IsPaid": true,
@@ -9085,7 +9085,7 @@
90859085
"ID": 755,
90869086
"Title": "Pour Water",
90879087
"TitleSlug": "pour-water",
9088-
"PassRate": "39%",
9088+
"PassRate": "38%",
90899089
"Difficulty": "Medium",
90909090
"IsAccepted": true,
90919091
"IsPaid": true,
@@ -9709,7 +9709,7 @@
97099709
"ID": 807,
97109710
"Title": "Max Increase to Keep City Skyline",
97119711
"TitleSlug": "max-increase-to-keep-city-skyline",
9712-
"PassRate": "81%",
9712+
"PassRate": "80%",
97139713
"Difficulty": "Medium",
97149714
"IsAccepted": true,
97159715
"IsPaid": false,
@@ -9769,7 +9769,7 @@
97699769
"ID": 812,
97709770
"Title": "Largest Triangle Area",
97719771
"TitleSlug": "largest-triangle-area",
9772-
"PassRate": "54%",
9772+
"PassRate": "55%",
97739773
"Difficulty": "Easy",
97749774
"IsAccepted": true,
97759775
"IsPaid": false,
@@ -10249,7 +10249,7 @@
1024910249
"ID": 852,
1025010250
"Title": "Peak Index in a Mountain Array",
1025110251
"TitleSlug": "peak-index-in-a-mountain-array",
10252-
"PassRate": "68%",
10252+
"PassRate": "69%",
1025310253
"Difficulty": "Easy",
1025410254
"IsAccepted": true,
1025510255
"IsPaid": false,
@@ -10765,7 +10765,7 @@
1076510765
"ID": 895,
1076610766
"Title": "Maximum Frequency Stack",
1076710767
"TitleSlug": "maximum-frequency-stack",
10768-
"PassRate": "51%",
10768+
"PassRate": "52%",
1076910769
"Difficulty": "Hard",
1077010770
"IsAccepted": true,
1077110771
"IsPaid": false,
@@ -10933,7 +10933,7 @@
1093310933
"ID": 909,
1093410934
"Title": "Snakes and Ladders",
1093510935
"TitleSlug": "snakes-and-ladders",
10936-
"PassRate": "29%",
10936+
"PassRate": "30%",
1093710937
"Difficulty": "Medium",
1093810938
"IsAccepted": true,
1093910939
"IsPaid": false,
@@ -11161,7 +11161,7 @@
1116111161
"ID": 928,
1116211162
"Title": "Minimize Malware Spread II",
1116311163
"TitleSlug": "minimize-malware-spread-ii",
11164-
"PassRate": "37%",
11164+
"PassRate": "38%",
1116511165
"Difficulty": "Hard",
1116611166
"IsAccepted": true,
1116711167
"IsPaid": false,
@@ -11593,7 +11593,7 @@
1159311593
"ID": 964,
1159411594
"Title": "Least Operators to Express Number",
1159511595
"TitleSlug": "least-operators-to-express-number",
11596-
"PassRate": "39%",
11596+
"PassRate": "40%",
1159711597
"Difficulty": "Hard",
1159811598
"IsAccepted": false,
1159911599
"IsPaid": false,
@@ -11929,7 +11929,7 @@
1192911929
"ID": 992,
1193011930
"Title": "Subarrays with K Different Integers",
1193111931
"TitleSlug": "subarrays-with-k-different-integers",
11932-
"PassRate": "44%",
11932+
"PassRate": "45%",
1193311933
"Difficulty": "Hard",
1193411934
"IsAccepted": false,
1193511935
"IsPaid": false,
@@ -11977,7 +11977,7 @@
1197711977
"ID": 996,
1197811978
"Title": "Number of Squareful Arrays",
1197911979
"TitleSlug": "number-of-squareful-arrays",
11980-
"PassRate": "47%",
11980+
"PassRate": "48%",
1198111981
"Difficulty": "Hard",
1198211982
"IsAccepted": false,
1198311983
"IsPaid": false,
@@ -11989,7 +11989,7 @@
1198911989
"ID": 997,
1199011990
"Title": "Find the Town Judge",
1199111991
"TitleSlug": "find-the-town-judge",
11992-
"PassRate": "48%",
11992+
"PassRate": "47%",
1199311993
"Difficulty": "Easy",
1199411994
"IsAccepted": false,
1199511995
"IsPaid": false,
@@ -12013,7 +12013,7 @@
1201312013
"ID": 999,
1201412014
"Title": "Available Captures for Rook",
1201512015
"TitleSlug": "available-captures-for-rook",
12016-
"PassRate": "73%",
12016+
"PassRate": "72%",
1201712017
"Difficulty": "Easy",
1201812018
"IsAccepted": false,
1201912019
"IsPaid": false,
@@ -12037,7 +12037,7 @@
1203712037
"ID": 1001,
1203812038
"Title": "Grid Illumination",
1203912039
"TitleSlug": "grid-illumination",
12040-
"PassRate": "32%",
12040+
"PassRate": "33%",
1204112041
"Difficulty": "Hard",
1204212042
"IsAccepted": false,
1204312043
"IsPaid": false,

0 commit comments

Comments
 (0)