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

Commit 5a013bc

Browse files
committed
936 added
1 parent 13738be commit 5a013bc

File tree

4 files changed

+150
-16
lines changed

4 files changed

+150
-16
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# [936. Stamping The Sequence](https://leetcode.com/problems/stamping-the-sequence/)
2+
3+
You want to form a target string of lowercase letters.
4+
5+
At the beginning, your sequence is target.length '?' marks. You also have a stamp of lowercase letters.
6+
7+
On each turn, you may place the stamp over the sequence, and replace every letter in the sequence with the corresponding letter from the stamp. You can make up to 10 * target.length turns.
8+
9+
For example, if the initial sequence is "?????", and your stamp is "abc", then you may make "abc??", "?abc?", "??abc" in the first turn. (Note that the stamp must be fully contained in the boundaries of the sequence in order to stamp.)
10+
11+
If the sequence is possible to stamp, then return an array of the index of the left-most letter being stamped at each turn. If the sequence is not possible to stamp, return an empty array.
12+
13+
For example, if the sequence is "ababc", and the stamp is "abc", then we could return the answer [0, 2], corresponding to the moves "?????" -> "abc??" -> "ababc".
14+
15+
Also, if the sequence is possible to stamp, it is guaranteed it is possible to stamp within 10 * target.length moves. Any answers specifying more than this number of moves will not be accepted.
16+
17+
Example 1:
18+
19+
```text
20+
Input: stamp = "abc", target = "ababc"
21+
Output: [0,2]
22+
([1,0,2] would also be accepted as an answer, as well as some other answers.)
23+
```
24+
25+
Example 2:
26+
27+
```text
28+
Input: stamp = "abca", target = "aabcaca"
29+
Output: [3,0,1]
30+
```
31+
32+
Note:
33+
34+
- 1 <= stamp.length <= target.length <= 1000
35+
- stamp and target only contain lowercase letters.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0936
2+
3+
func movesToStamp(stamp string, target string) []int {
4+
5+
return nil
6+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package problem0936
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// tcs is testcase slice
10+
var tcs = []struct {
11+
stamp string
12+
target string
13+
ans []int
14+
}{
15+
16+
{
17+
"abc",
18+
"ababc",
19+
[]int{0, 2},
20+
},
21+
22+
{
23+
"abca",
24+
"aabcaca",
25+
[]int{3, 0, 1},
26+
},
27+
28+
// 可以有多个 testcase
29+
}
30+
31+
func Test_movesToStamp(t *testing.T) {
32+
ast := assert.New(t)
33+
34+
for _, tc := range tcs {
35+
ast.Equal(tc.ans, movesToStamp(tc.stamp, tc.target), "输入:%v", tc)
36+
}
37+
}
38+
39+
func Benchmark_movesToStamp(b *testing.B) {
40+
for i := 0; i < b.N; i++ {
41+
for _, tc := range tcs {
42+
movesToStamp(tc.stamp, tc.target)
43+
}
44+
}
45+
}

leetcode.json

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 927,
4-
"Updated": "2019-02-02T23:23:01.193723611+08:00",
4+
"Updated": "2019-02-03T13:08:58.697681697+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 210,
8-
"Total": 227
8+
"Total": 228
99
},
1010
"Medium": {
1111
"Solved": 351,
12-
"Total": 380
12+
"Total": 383
1313
},
1414
"Hard": {
1515
"Solved": 155,
1616
"Total": 166
1717
},
1818
"Total": {
1919
"Solved": 716,
20-
"Total": 773
20+
"Total": 777
2121
}
2222
},
2323
"Problems": [
@@ -5509,7 +5509,7 @@
55095509
"ID": 457,
55105510
"Title": "Circular Array Loop",
55115511
"TitleSlug": "circular-array-loop",
5512-
"PassRate": "26%",
5512+
"PassRate": "27%",
55135513
"Difficulty": "Medium",
55145514
"IsAccepted": true,
55155515
"IsPaid": false,
@@ -6049,7 +6049,7 @@
60496049
"ID": 502,
60506050
"Title": "IPO",
60516051
"TitleSlug": "ipo",
6052-
"PassRate": "36%",
6052+
"PassRate": "37%",
60536053
"Difficulty": "Hard",
60546054
"IsAccepted": true,
60556055
"IsPaid": false,
@@ -6145,7 +6145,7 @@
61456145
"ID": 510,
61466146
"Title": "Inorder Successor in BST II",
61476147
"TitleSlug": "inorder-successor-in-bst-ii",
6148-
"PassRate": "33%",
6148+
"PassRate": "61%",
61496149
"Difficulty": "Medium",
61506150
"IsAccepted": false,
61516151
"IsPaid": true,
@@ -6277,7 +6277,7 @@
62776277
"ID": 521,
62786278
"Title": "Longest Uncommon Subsequence I ",
62796279
"TitleSlug": "longest-uncommon-subsequence-i",
6280-
"PassRate": "56%",
6280+
"PassRate": "55%",
62816281
"Difficulty": "Easy",
62826282
"IsAccepted": true,
62836283
"IsPaid": false,
@@ -6661,7 +6661,7 @@
66616661
"ID": 553,
66626662
"Title": "Optimal Division",
66636663
"TitleSlug": "optimal-division",
6664-
"PassRate": "55%",
6664+
"PassRate": "54%",
66656665
"Difficulty": "Medium",
66666666
"IsAccepted": true,
66676667
"IsPaid": false,
@@ -7837,7 +7837,7 @@
78377837
"ID": 651,
78387838
"Title": "4 Keys Keyboard",
78397839
"TitleSlug": "4-keys-keyboard",
7840-
"PassRate": "49%",
7840+
"PassRate": "50%",
78417841
"Difficulty": "Medium",
78427842
"IsAccepted": false,
78437843
"IsPaid": true,
@@ -10657,7 +10657,7 @@
1065710657
"ID": 886,
1065810658
"Title": "Possible Bipartition",
1065910659
"TitleSlug": "possible-bipartition",
10660-
"PassRate": "39%",
10660+
"PassRate": "40%",
1066110661
"Difficulty": "Medium",
1066210662
"IsAccepted": true,
1066310663
"IsPaid": false,
@@ -11149,7 +11149,7 @@
1114911149
"ID": 927,
1115011150
"Title": "Three Equal Parts",
1115111151
"TitleSlug": "three-equal-parts",
11152-
"PassRate": "28%",
11152+
"PassRate": "29%",
1115311153
"Difficulty": "Hard",
1115411154
"IsAccepted": true,
1115511155
"IsPaid": false,
@@ -11185,7 +11185,7 @@
1118511185
"ID": 930,
1118611186
"Title": "Binary Subarrays With Sum",
1118711187
"TitleSlug": "binary-subarrays-with-sum",
11188-
"PassRate": "35%",
11188+
"PassRate": "36%",
1118911189
"Difficulty": "Medium",
1119011190
"IsAccepted": true,
1119111191
"IsPaid": false,
@@ -11677,7 +11677,7 @@
1167711677
"ID": 971,
1167811678
"Title": "Flip Binary Tree To Match Preorder Traversal",
1167911679
"TitleSlug": "flip-binary-tree-to-match-preorder-traversal",
11680-
"PassRate": "42%",
11680+
"PassRate": "41%",
1168111681
"Difficulty": "Medium",
1168211682
"IsAccepted": false,
1168311683
"IsPaid": false,
@@ -11725,7 +11725,7 @@
1172511725
"ID": 975,
1172611726
"Title": "Odd Even Jump",
1172711727
"TitleSlug": "odd-even-jump",
11728-
"PassRate": "50%",
11728+
"PassRate": "51%",
1172911729
"Difficulty": "Hard",
1173011730
"IsAccepted": false,
1173111731
"IsPaid": false,
@@ -11809,7 +11809,7 @@
1180911809
"ID": 982,
1181011810
"Title": "Triples with Bitwise AND Equal To Zero",
1181111811
"TitleSlug": "triples-with-bitwise-and-equal-to-zero",
11812-
"PassRate": "52%",
11812+
"PassRate": "53%",
1181311813
"Difficulty": "Hard",
1181411814
"IsAccepted": false,
1181511815
"IsPaid": false,
@@ -11840,6 +11840,54 @@
1184011840
"IsFavor": false,
1184111841
"IsNew": false,
1184211842
"HasNoGoOption": false
11843+
},
11844+
{
11845+
"ID": 985,
11846+
"Title": "Sum of Even Numbers After Queries",
11847+
"TitleSlug": "sum-of-even-numbers-after-queries",
11848+
"PassRate": "68%",
11849+
"Difficulty": "Easy",
11850+
"IsAccepted": false,
11851+
"IsPaid": false,
11852+
"IsFavor": false,
11853+
"IsNew": true,
11854+
"HasNoGoOption": false
11855+
},
11856+
{
11857+
"ID": 986,
11858+
"Title": "Interval List Intersections",
11859+
"TitleSlug": "interval-list-intersections",
11860+
"PassRate": "53%",
11861+
"Difficulty": "Medium",
11862+
"IsAccepted": false,
11863+
"IsPaid": false,
11864+
"IsFavor": false,
11865+
"IsNew": true,
11866+
"HasNoGoOption": false
11867+
},
11868+
{
11869+
"ID": 987,
11870+
"Title": "Vertical Order Traversal of a Binary Tree",
11871+
"TitleSlug": "vertical-order-traversal-of-a-binary-tree",
11872+
"PassRate": "29%",
11873+
"Difficulty": "Medium",
11874+
"IsAccepted": false,
11875+
"IsPaid": false,
11876+
"IsFavor": false,
11877+
"IsNew": true,
11878+
"HasNoGoOption": false
11879+
},
11880+
{
11881+
"ID": 988,
11882+
"Title": "Smallest String Starting From Leaf",
11883+
"TitleSlug": "smallest-string-starting-from-leaf",
11884+
"PassRate": "48%",
11885+
"Difficulty": "Medium",
11886+
"IsAccepted": false,
11887+
"IsPaid": false,
11888+
"IsFavor": false,
11889+
"IsNew": true,
11890+
"HasNoGoOption": false
1184311891
}
1184411892
]
1184511893
}

0 commit comments

Comments
 (0)