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

Commit 5489e79

Browse files
committed
899 added
1 parent 919eea7 commit 5489e79

File tree

4 files changed

+116
-19
lines changed

4 files changed

+116
-19
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# [899. Orderly Queue](https://leetcode.com/problems/orderly-queue/)
2+
3+
## 题目
4+
5+
A string `S` of lowercase letters is given. Then, we may make any number of moves.
6+
7+
In each move, we choose one of the first `K` letters (starting from the left), remove it,`and place it at the end of the string.
8+
9+
Return the lexicographically smallest string we could have after any number of moves.
10+
11+
Example 1:
12+
13+
```text
14+
Input: S = "cba", K = 1
15+
Output: "acb"
16+
Explanation:
17+
In the first move, we move the 1st character ("c") to the end, obtaining the string "bac".
18+
In the second move, we move the 1st character ("b") to the end, obtaining the final result "acb".
19+
```
20+
21+
Example 2:
22+
23+
```text
24+
Input: S = "baaca", K = 3
25+
Output: "aaabc"
26+
Explanation:
27+
In the first move, we move the 1st character ("b") to the end, obtaining the string "aacab".
28+
In the second move, we move the 3rd character ("c") to the end, obtaining the final result "aaabc".
29+
```
30+
31+
Note:
32+
33+
- `1 <= K <= S.length<= 1000`
34+
- `S`consists of lowercase letters only.
35+
36+
## 解题思路
37+
38+
见程序注释
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0899
2+
3+
func orderlyQueue(S string, K int) string {
4+
5+
return ""
6+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package problem0899
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+
K int
14+
ans string
15+
}{
16+
17+
{
18+
"cba",
19+
1,
20+
"acb",
21+
},
22+
23+
{
24+
"edcba",
25+
5,
26+
"abcde",
27+
},
28+
29+
{
30+
"baaca",
31+
3,
32+
"aaabc",
33+
},
34+
35+
// 可以有多个 testcase
36+
}
37+
38+
func Test_orderlyQueue(t *testing.T) {
39+
ast := assert.New(t)
40+
41+
for _, tc := range tcs {
42+
fmt.Printf("~~%v~~\n", tc)
43+
ast.Equal(tc.ans, orderlyQueue(tc.S, tc.K), "输入:%v", tc)
44+
}
45+
}
46+
47+
func Benchmark_orderlyQueue(b *testing.B) {
48+
for i := 0; i < b.N; i++ {
49+
for _, tc := range tcs {
50+
orderlyQueue(tc.S, tc.K)
51+
}
52+
}
53+
}

leetcode.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 836,
4-
"Updated": "2018-10-16T09:01:52.190428719+08:00",
4+
"Updated": "2018-10-16T16:56:49.030888429+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 201,
@@ -829,7 +829,7 @@
829829
"ID": 67,
830830
"Title": "Add Binary",
831831
"TitleSlug": "add-binary",
832-
"PassRate": "35%",
832+
"PassRate": "36%",
833833
"Difficulty": "Easy",
834834
"IsAccepted": true,
835835
"IsPaid": false,
@@ -2881,7 +2881,7 @@
28812881
"ID": 238,
28822882
"Title": "Product of Array Except Self",
28832883
"TitleSlug": "product-of-array-except-self",
2884-
"PassRate": "51%",
2884+
"PassRate": "52%",
28852885
"Difficulty": "Medium",
28862886
"IsAccepted": true,
28872887
"IsPaid": false,
@@ -3589,7 +3589,7 @@
35893589
"ID": 297,
35903590
"Title": "Serialize and Deserialize Binary Tree",
35913591
"TitleSlug": "serialize-and-deserialize-binary-tree",
3592-
"PassRate": "36%",
3592+
"PassRate": "37%",
35933593
"Difficulty": "Hard",
35943594
"IsAccepted": false,
35953595
"IsPaid": false,
@@ -5125,7 +5125,7 @@
51255125
"ID": 425,
51265126
"Title": "Word Squares",
51275127
"TitleSlug": "word-squares",
5128-
"PassRate": "42%",
5128+
"PassRate": "43%",
51295129
"Difficulty": "Hard",
51305130
"IsAccepted": false,
51315131
"IsPaid": true,
@@ -6325,7 +6325,7 @@
63256325
"ID": 525,
63266326
"Title": "Contiguous Array",
63276327
"TitleSlug": "contiguous-array",
6328-
"PassRate": "41%",
6328+
"PassRate": "42%",
63296329
"Difficulty": "Medium",
63306330
"IsAccepted": true,
63316331
"IsPaid": false,
@@ -6565,7 +6565,7 @@
65656565
"ID": 545,
65666566
"Title": "Boundary of Binary Tree",
65676567
"TitleSlug": "boundary-of-binary-tree",
6568-
"PassRate": "32%",
6568+
"PassRate": "33%",
65696569
"Difficulty": "Medium",
65706570
"IsAccepted": false,
65716571
"IsPaid": true,
@@ -6661,7 +6661,7 @@
66616661
"ID": 553,
66626662
"Title": "Optimal Division",
66636663
"TitleSlug": "optimal-division",
6664-
"PassRate": "54%",
6664+
"PassRate": "55%",
66656665
"Difficulty": "Medium",
66666666
"IsAccepted": true,
66676667
"IsPaid": false,
@@ -8413,7 +8413,7 @@
84138413
"ID": 699,
84148414
"Title": "Falling Squares",
84158415
"TitleSlug": "falling-squares",
8416-
"PassRate": "37%",
8416+
"PassRate": "38%",
84178417
"Difficulty": "Hard",
84188418
"IsAccepted": true,
84198419
"IsPaid": false,
@@ -8749,7 +8749,7 @@
87498749
"ID": 727,
87508750
"Title": "Minimum Window Subsequence",
87518751
"TitleSlug": "minimum-window-subsequence",
8752-
"PassRate": "32%",
8752+
"PassRate": "33%",
87538753
"Difficulty": "Hard",
87548754
"IsAccepted": false,
87558755
"IsPaid": true,
@@ -8785,7 +8785,7 @@
87858785
"ID": 730,
87868786
"Title": "Count Different Palindromic Subsequences",
87878787
"TitleSlug": "count-different-palindromic-subsequences",
8788-
"PassRate": "36%",
8788+
"PassRate": "37%",
87898789
"Difficulty": "Hard",
87908790
"IsAccepted": true,
87918791
"IsPaid": false,
@@ -8845,7 +8845,7 @@
88458845
"ID": 735,
88468846
"Title": "Asteroid Collision",
88478847
"TitleSlug": "asteroid-collision",
8848-
"PassRate": "36%",
8848+
"PassRate": "37%",
88498849
"Difficulty": "Medium",
88508850
"IsAccepted": true,
88518851
"IsPaid": false,
@@ -9025,7 +9025,7 @@
90259025
"ID": 750,
90269026
"Title": "Number Of Corner Rectangles",
90279027
"TitleSlug": "number-of-corner-rectangles",
9028-
"PassRate": "59%",
9028+
"PassRate": "60%",
90299029
"Difficulty": "Medium",
90309030
"IsAccepted": false,
90319031
"IsPaid": true,
@@ -9553,7 +9553,7 @@
95539553
"ID": 794,
95549554
"Title": "Valid Tic-Tac-Toe State",
95559555
"TitleSlug": "valid-tic-tac-toe-state",
9556-
"PassRate": "28%",
9556+
"PassRate": "27%",
95579557
"Difficulty": "Medium",
95589558
"IsAccepted": true,
95599559
"IsPaid": false,
@@ -9961,7 +9961,7 @@
99619961
"ID": 828,
99629962
"Title": "Unique Letter String",
99639963
"TitleSlug": "unique-letter-string",
9964-
"PassRate": "35%",
9964+
"PassRate": "36%",
99659965
"Difficulty": "Hard",
99669966
"IsAccepted": true,
99679967
"IsPaid": false,
@@ -10261,7 +10261,7 @@
1026110261
"ID": 853,
1026210262
"Title": "Car Fleet",
1026310263
"TitleSlug": "car-fleet",
10264-
"PassRate": "33%",
10264+
"PassRate": "34%",
1026510265
"Difficulty": "Medium",
1026610266
"IsAccepted": true,
1026710267
"IsPaid": false,
@@ -10309,7 +10309,7 @@
1030910309
"ID": 857,
1031010310
"Title": "Minimum Cost to Hire K Workers",
1031110311
"TitleSlug": "minimum-cost-to-hire-k-workers",
10312-
"PassRate": "42%",
10312+
"PassRate": "43%",
1031310313
"Difficulty": "Hard",
1031410314
"IsAccepted": true,
1031510315
"IsPaid": false,
@@ -10645,7 +10645,7 @@
1064510645
"ID": 885,
1064610646
"Title": "Spiral Matrix III",
1064710647
"TitleSlug": "spiral-matrix-iii",
10648-
"PassRate": "62%",
10648+
"PassRate": "63%",
1064910649
"Difficulty": "Medium",
1065010650
"IsAccepted": true,
1065110651
"IsPaid": false,
@@ -10657,7 +10657,7 @@
1065710657
"ID": 886,
1065810658
"Title": "Possible Bipartition",
1065910659
"TitleSlug": "possible-bipartition",
10660-
"PassRate": "39%",
10660+
"PassRate": "38%",
1066110661
"Difficulty": "Medium",
1066210662
"IsAccepted": true,
1066310663
"IsPaid": false,

0 commit comments

Comments
 (0)