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

Commit bcee9cc

Browse files
committed
955 added
1 parent 1c38ed6 commit bcee9cc

File tree

4 files changed

+120
-20
lines changed

4 files changed

+120
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# [955. Delete Columns to Make Sorted II](https://leetcode.com/problems/delete-columns-to-make-sorted-ii/)
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"].
8+
9+
Suppose we chose a set of deletion indices D such that after deletions, the final array has its elements in lexicographic order (A[0] <= A[1] <= A[2] ... <= A[A.length - 1]).
10+
11+
Return the minimum possible value of D.length.
12+
13+
Example 1:
14+
15+
```text
16+
Input: ["ca","bb","ac"]
17+
Output: 1
18+
Explanation:
19+
After deleting the first column, A = ["a", "b", "c"].
20+
Now A is in lexicographic order (ie. A[0] <= A[1] <= A[2]).
21+
We require at least 1 deletion since initially A was not in lexicographic order, so the answer is 1.
22+
```
23+
24+
Example 2:
25+
26+
```text
27+
Input: ["xc","yb","za"]
28+
Output: 0
29+
Explanation:
30+
A is already in lexicographic order, so we don't need to delete anything.
31+
Note that the rows of A are not necessarily in lexicographic order:
32+
ie. it is NOT necessarily true that (A[0][0] <= A[0][1] <= ...)
33+
```
34+
35+
Example 3:
36+
37+
```text
38+
Input: ["zyx","wvu","tsr"]
39+
Output: 3
40+
Explanation:
41+
We have to delete every column.
42+
```
43+
44+
Note:
45+
46+
1. 1 <= A.length <= 100
47+
1. 1 <= A[i].length <= 100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0955
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 problem0955
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{"ca", "bb", "ac"},
17+
1,
18+
},
19+
20+
{
21+
[]string{"xc", "yb", "za"},
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

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 908,
4-
"Updated": "2019-03-16T19:43:35.734854191+08:00",
4+
"Updated": "2019-03-17T11:32:06.931447145+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 213,
@@ -1081,7 +1081,7 @@
10811081
"ID": 88,
10821082
"Title": "Merge Sorted Array",
10831083
"TitleSlug": "merge-sorted-array",
1084-
"PassRate": "34%",
1084+
"PassRate": "35%",
10851085
"Difficulty": "Easy",
10861086
"IsAccepted": true,
10871087
"IsPaid": false,
@@ -2629,7 +2629,7 @@
26292629
"ID": 217,
26302630
"Title": "Contains Duplicate",
26312631
"TitleSlug": "contains-duplicate",
2632-
"PassRate": "50%",
2632+
"PassRate": "51%",
26332633
"Difficulty": "Easy",
26342634
"IsAccepted": true,
26352635
"IsPaid": false,
@@ -4717,7 +4717,7 @@
47174717
"ID": 391,
47184718
"Title": "Perfect Rectangle",
47194719
"TitleSlug": "perfect-rectangle",
4720-
"PassRate": "28%",
4720+
"PassRate": "27%",
47214721
"Difficulty": "Hard",
47224722
"IsAccepted": true,
47234723
"IsPaid": false,
@@ -6181,7 +6181,7 @@
61816181
"ID": 513,
61826182
"Title": "Find Bottom Left Tree Value",
61836183
"TitleSlug": "find-bottom-left-tree-value",
6184-
"PassRate": "57%",
6184+
"PassRate": "58%",
61856185
"Difficulty": "Medium",
61866186
"IsAccepted": true,
61876187
"IsPaid": false,
@@ -7657,7 +7657,7 @@
76577657
"ID": 636,
76587658
"Title": "Exclusive Time of Functions",
76597659
"TitleSlug": "exclusive-time-of-functions",
7660-
"PassRate": "47%",
7660+
"PassRate": "48%",
76617661
"Difficulty": "Medium",
76627662
"IsAccepted": true,
76637663
"IsPaid": false,
@@ -7753,7 +7753,7 @@
77537753
"ID": 644,
77547754
"Title": "Maximum Average Subarray II",
77557755
"TitleSlug": "maximum-average-subarray-ii",
7756-
"PassRate": "27%",
7756+
"PassRate": "28%",
77577757
"Difficulty": "Hard",
77587758
"IsAccepted": false,
77597759
"IsPaid": true,
@@ -7861,7 +7861,7 @@
78617861
"ID": 653,
78627862
"Title": "Two Sum IV - Input is a BST",
78637863
"TitleSlug": "two-sum-iv-input-is-a-bst",
7864-
"PassRate": "51%",
7864+
"PassRate": "52%",
78657865
"Difficulty": "Easy",
78667866
"IsAccepted": true,
78677867
"IsPaid": false,
@@ -9205,7 +9205,7 @@
92059205
"ID": 765,
92069206
"Title": "Couples Holding Hands",
92079207
"TitleSlug": "couples-holding-hands",
9208-
"PassRate": "51%",
9208+
"PassRate": "50%",
92099209
"Difficulty": "Hard",
92109210
"IsAccepted": true,
92119211
"IsPaid": false,
@@ -9253,7 +9253,7 @@
92539253
"ID": 769,
92549254
"Title": "Max Chunks To Make Sorted",
92559255
"TitleSlug": "max-chunks-to-make-sorted",
9256-
"PassRate": "50%",
9256+
"PassRate": "51%",
92579257
"Difficulty": "Medium",
92589258
"IsAccepted": true,
92599259
"IsPaid": false,
@@ -9601,7 +9601,7 @@
96019601
"ID": 798,
96029602
"Title": "Smallest Rotation with Highest Score",
96039603
"TitleSlug": "smallest-rotation-with-highest-score",
9604-
"PassRate": "38%",
9604+
"PassRate": "39%",
96059605
"Difficulty": "Hard",
96069606
"IsAccepted": true,
96079607
"IsPaid": false,
@@ -9889,7 +9889,7 @@
98899889
"ID": 822,
98909890
"Title": "Card Flipping Game",
98919891
"TitleSlug": "card-flipping-game",
9892-
"PassRate": "39%",
9892+
"PassRate": "40%",
98939893
"Difficulty": "Medium",
98949894
"IsAccepted": true,
98959895
"IsPaid": false,
@@ -10021,7 +10021,7 @@
1002110021
"ID": 833,
1002210022
"Title": "Find And Replace in String",
1002310023
"TitleSlug": "find-and-replace-in-string",
10024-
"PassRate": "44%",
10024+
"PassRate": "45%",
1002510025
"Difficulty": "Medium",
1002610026
"IsAccepted": true,
1002710027
"IsPaid": false,
@@ -10765,7 +10765,7 @@
1076510765
"ID": 895,
1076610766
"Title": "Maximum Frequency Stack",
1076710767
"TitleSlug": "maximum-frequency-stack",
10768-
"PassRate": "53%",
10768+
"PassRate": "52%",
1076910769
"Difficulty": "Hard",
1077010770
"IsAccepted": true,
1077110771
"IsPaid": false,
@@ -10861,7 +10861,7 @@
1086110861
"ID": 903,
1086210862
"Title": "Valid Permutations for DI Sequence",
1086310863
"TitleSlug": "valid-permutations-for-di-sequence",
10864-
"PassRate": "41%",
10864+
"PassRate": "42%",
1086510865
"Difficulty": "Hard",
1086610866
"IsAccepted": true,
1086710867
"IsPaid": false,
@@ -10957,7 +10957,7 @@
1095710957
"ID": 911,
1095810958
"Title": "Online Election",
1095910959
"TitleSlug": "online-election",
10960-
"PassRate": "44%",
10960+
"PassRate": "45%",
1096110961
"Difficulty": "Medium",
1096210962
"IsAccepted": true,
1096310963
"IsPaid": false,
@@ -11029,7 +11029,7 @@
1102911029
"ID": 917,
1103011030
"Title": "Reverse Only Letters",
1103111031
"TitleSlug": "reverse-only-letters",
11032-
"PassRate": "55%",
11032+
"PassRate": "56%",
1103311033
"Difficulty": "Easy",
1103411034
"IsAccepted": true,
1103511035
"IsPaid": false,
@@ -11737,7 +11737,7 @@
1173711737
"ID": 976,
1173811738
"Title": "Largest Perimeter Triangle",
1173911739
"TitleSlug": "largest-perimeter-triangle",
11740-
"PassRate": "56%",
11740+
"PassRate": "57%",
1174111741
"Difficulty": "Easy",
1174211742
"IsAccepted": false,
1174311743
"IsPaid": false,
@@ -12097,7 +12097,7 @@
1209712097
"ID": 1006,
1209812098
"Title": "Clumsy Factorial",
1209912099
"TitleSlug": "clumsy-factorial",
12100-
"PassRate": "55%",
12100+
"PassRate": "54%",
1210112101
"Difficulty": "Medium",
1210212102
"IsAccepted": false,
1210312103
"IsPaid": false,
@@ -12109,7 +12109,7 @@
1210912109
"ID": 1007,
1211012110
"Title": "Minimum Domino Rotations For Equal Row",
1211112111
"TitleSlug": "minimum-domino-rotations-for-equal-row",
12112-
"PassRate": "48%",
12112+
"PassRate": "47%",
1211312113
"Difficulty": "Medium",
1211412114
"IsAccepted": false,
1211512115
"IsPaid": false,

0 commit comments

Comments
 (0)