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

Commit 68d91a5

Browse files
aQuaaQua
aQua
authored and
aQua
committed
791 added
1 parent 9f7d9c3 commit 68d91a5

File tree

4 files changed

+102
-19
lines changed

4 files changed

+102
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# [791. Custom Sort String](https://leetcode.com/problems/custom-sort-string/)
2+
3+
## 题目
4+
5+
S and T are strings composed of lowercase letters. In S, no letter occurs more than once.
6+
7+
S was sorted in some custom order previously. We want to permute the characters of T so that they match the order that S was sorted. More specifically, if x occurs before y in S, then x should occur before y in the returned string.
8+
9+
Return any permutation of T (as a string) that satisfies this property.
10+
11+
```text
12+
Example :
13+
Input:
14+
S = "cba"
15+
T = "abcd"
16+
Output: "cbad"
17+
Explanation:
18+
"a", "b", "c" appear in S, so the order of "a", "b", "c" should be "c", "b", and "a".
19+
Since "d" does not appear in S, it can be at any position in T. "dcba", "cdba", "cbda" are also valid outputs.
20+
```
21+
22+
Note:
23+
24+
1. S has length at most 26, and no character is repeated in S.
25+
1. T has length at most 200.
26+
1. S and T consist of lowercase letters only.
27+
28+
## 解题思路
29+
30+
见程序注释
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0791
2+
3+
func customSortString(S string, T string) string {
4+
5+
return ""
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package problem0791
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
// tcs is testcase slice
11+
var tcs = []struct {
12+
S string
13+
T string
14+
ans string
15+
}{
16+
17+
{
18+
"cba",
19+
"abcd",
20+
"cbad",
21+
},
22+
23+
{
24+
"cba",
25+
"abcdbca",
26+
"ccbbaad",
27+
},
28+
29+
// 可以有多个 testcase
30+
}
31+
32+
func Test_customSortString(t *testing.T) {
33+
ast := assert.New(t)
34+
35+
for _, tc := range tcs {
36+
fmt.Printf("~~%v~~\n", tc)
37+
ast.Equal(tc.ans, customSortString(tc.S, tc.T), "输入:%v", tc)
38+
}
39+
}
40+
41+
func Benchmark_customSortString(b *testing.B) {
42+
for i := 0; i < b.N; i++ {
43+
for _, tc := range tcs {
44+
customSortString(tc.S, tc.T)
45+
}
46+
}
47+
}

leetcode.json

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
3-
"Ranking": 1394,
4-
"Updated": "2018-04-10T14:56:38.364499396+08:00",
3+
"Ranking": 1357,
4+
"Updated": "2018-04-11T16:45:42.413163523+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 161,
@@ -2053,7 +2053,7 @@
20532053
"ID": 169,
20542054
"Title": "Majority Element",
20552055
"TitleSlug": "majority-element",
2056-
"PassRate": "47%",
2056+
"PassRate": "48%",
20572057
"Difficulty": "Easy",
20582058
"IsAccepted": true,
20592059
"IsPaid": false,
@@ -6745,7 +6745,7 @@
67456745
"ID": 560,
67466746
"Title": "Subarray Sum Equals K",
67476747
"TitleSlug": "subarray-sum-equals-k",
6748-
"PassRate": "39%",
6748+
"PassRate": "40%",
67496749
"Difficulty": "Medium",
67506750
"IsAccepted": true,
67516751
"IsPaid": false,
@@ -7117,7 +7117,7 @@
71177117
"ID": 591,
71187118
"Title": "Tag Validator",
71197119
"TitleSlug": "tag-validator",
7120-
"PassRate": "30%",
7120+
"PassRate": "31%",
71217121
"Difficulty": "Hard",
71227122
"IsAccepted": true,
71237123
"IsPaid": false,
@@ -7153,7 +7153,7 @@
71537153
"ID": 594,
71547154
"Title": "Longest Harmonious Subsequence",
71557155
"TitleSlug": "longest-harmonious-subsequence",
7156-
"PassRate": "40%",
7156+
"PassRate": "41%",
71577157
"Difficulty": "Easy",
71587158
"IsAccepted": true,
71597159
"IsPaid": false,
@@ -7969,7 +7969,7 @@
79697969
"ID": 662,
79707970
"Title": "Maximum Width of Binary Tree",
79717971
"TitleSlug": "maximum-width-of-binary-tree",
7972-
"PassRate": "38%",
7972+
"PassRate": "37%",
79737973
"Difficulty": "Medium",
79747974
"IsAccepted": true,
79757975
"IsPaid": false,
@@ -8557,7 +8557,7 @@
85578557
"ID": 711,
85588558
"Title": "Number of Distinct Islands II",
85598559
"TitleSlug": "number-of-distinct-islands-ii",
8560-
"PassRate": "41%",
8560+
"PassRate": "42%",
85618561
"Difficulty": "Hard",
85628562
"IsAccepted": false,
85638563
"IsPaid": true,
@@ -8617,7 +8617,7 @@
86178617
"ID": 716,
86188618
"Title": "Max Stack",
86198619
"TitleSlug": "max-stack",
8620-
"PassRate": "37%",
8620+
"PassRate": "36%",
86218621
"Difficulty": "Hard",
86228622
"IsAccepted": false,
86238623
"IsPaid": true,
@@ -8785,7 +8785,7 @@
87858785
"ID": 730,
87868786
"Title": "Count Different Palindromic Subsequences",
87878787
"TitleSlug": "count-different-palindromic-subsequences",
8788-
"PassRate": "35%",
8788+
"PassRate": "34%",
87898789
"Difficulty": "Hard",
87908790
"IsAccepted": true,
87918791
"IsPaid": false,
@@ -8821,7 +8821,7 @@
88218821
"ID": 733,
88228822
"Title": "Flood Fill",
88238823
"TitleSlug": "flood-fill",
8824-
"PassRate": "48%",
8824+
"PassRate": "47%",
88258825
"Difficulty": "Easy",
88268826
"IsAccepted": true,
88278827
"IsPaid": false,
@@ -9205,7 +9205,7 @@
92059205
"ID": 765,
92069206
"Title": "Couples Holding Hands",
92079207
"TitleSlug": "couples-holding-hands",
9208-
"PassRate": "47%",
9208+
"PassRate": "48%",
92099209
"Difficulty": "Hard",
92109210
"IsAccepted": true,
92119211
"IsPaid": false,
@@ -9289,7 +9289,7 @@
92899289
"ID": 772,
92909290
"Title": "Basic Calculator III",
92919291
"TitleSlug": "basic-calculator-iii",
9292-
"PassRate": "38%",
9292+
"PassRate": "39%",
92939293
"Difficulty": "Hard",
92949294
"IsAccepted": false,
92959295
"IsPaid": true,
@@ -9421,7 +9421,7 @@
94219421
"ID": 783,
94229422
"Title": "Minimum Distance Between BST Nodes",
94239423
"TitleSlug": "minimum-distance-between-bst-nodes",
9424-
"PassRate": "46%",
9424+
"PassRate": "47%",
94259425
"Difficulty": "Easy",
94269426
"IsAccepted": true,
94279427
"IsPaid": false,
@@ -9529,7 +9529,7 @@
95299529
"ID": 792,
95309530
"Title": "Number of Matching Subsequences",
95319531
"TitleSlug": "number-of-matching-subsequences",
9532-
"PassRate": "34%",
9532+
"PassRate": "35%",
95339533
"Difficulty": "Medium",
95349534
"IsAccepted": false,
95359535
"IsPaid": false,
@@ -9541,7 +9541,7 @@
95419541
"ID": 793,
95429542
"Title": "Preimage Size of Factorial Zeroes Function",
95439543
"TitleSlug": "preimage-size-of-factorial-zeroes-function",
9544-
"PassRate": "45%",
9544+
"PassRate": "44%",
95459545
"Difficulty": "Hard",
95469546
"IsAccepted": false,
95479547
"IsPaid": false,
@@ -9589,7 +9589,7 @@
95899589
"ID": 797,
95909590
"Title": "All Paths From Source to Target",
95919591
"TitleSlug": "all-paths-from-source-to-target",
9592-
"PassRate": "68%",
9592+
"PassRate": "69%",
95939593
"Difficulty": "Medium",
95949594
"IsAccepted": false,
95959595
"IsPaid": false,
@@ -9673,7 +9673,7 @@
96739673
"ID": 804,
96749674
"Title": "Unique Morse Code Words",
96759675
"TitleSlug": "unique-morse-code-words",
9676-
"PassRate": "77%",
9676+
"PassRate": "76%",
96779677
"Difficulty": "Easy",
96789678
"IsAccepted": false,
96799679
"IsPaid": false,
@@ -9781,7 +9781,7 @@
97819781
"ID": 813,
97829782
"Title": "Largest Sum of Averages",
97839783
"TitleSlug": "largest-sum-of-averages",
9784-
"PassRate": "35%",
9784+
"PassRate": "36%",
97859785
"Difficulty": "Medium",
97869786
"IsAccepted": false,
97879787
"IsPaid": false,

0 commit comments

Comments
 (0)