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

Commit 48bfa6c

Browse files
committed
1089 added
1 parent aa14d6d commit 48bfa6c

File tree

4 files changed

+98
-23
lines changed

4 files changed

+98
-23
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [1089. Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/)
2+
3+
Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right.
4+
5+
Note that elements beyond the length of the original array are not written.
6+
7+
Do the above modifications to the input array in place, do not return anything from your function.
8+
9+
Example 1:
10+
11+
```text
12+
Input: [1,0,2,3,0,4,5,0]
13+
Output: null
14+
Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
15+
```
16+
17+
Example 2:
18+
19+
```text
20+
Input: [1,2,3]
21+
Output: null
22+
Explanation: After calling your function, the input array is modified to: [1,2,3]
23+
```
24+
25+
Note:
26+
27+
1. `1 <= arr.length <= 10000`
28+
1. `0 <= arr[i] <= 9`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package problem1089
2+
3+
func duplicateZeros(arr []int) {
4+
return nil
5+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package problem1089
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// tcs is testcase slice
10+
var tcs = []struct {
11+
arr []int
12+
ans []int
13+
}{
14+
15+
{
16+
[]int{1, 0, 2, 3, 0, 4, 5, 0},
17+
[]int{1, 0, 0, 2, 3, 0, 0, 4},
18+
},
19+
20+
{
21+
[]int{1, 2, 3},
22+
[]int{1, 2, 3},
23+
},
24+
25+
// 可以有多个 testcase
26+
}
27+
28+
func Test_duplicateZeros(t *testing.T) {
29+
ast := assert.New(t)
30+
31+
for _, tc := range tcs {
32+
ast.Equal(tc.ans, duplicateZeros(tc.arr), "输入:%v", tc)
33+
}
34+
}
35+
36+
func Benchmark_duplicateZeros(b *testing.B) {
37+
for i := 0; i < b.N; i++ {
38+
for _, tc := range tcs {
39+
duplicateZeros(tc.arr)
40+
}
41+
}
42+
}

leetcode.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
3-
"Ranking": 572,
4-
"Updated": "2019-07-14T18:47:56.061792965+08:00",
3+
"Ranking": 575,
4+
"Updated": "2019-07-15T19:24:57.601662486+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 251,
@@ -421,7 +421,7 @@
421421
"ID": 33,
422422
"Title": "Search in Rotated Sorted Array",
423423
"TitleSlug": "search-in-rotated-sorted-array",
424-
"PassRate": "32%",
424+
"PassRate": "33%",
425425
"Difficulty": "Medium",
426426
"IsAccepted": true,
427427
"IsPaid": false,
@@ -3889,7 +3889,7 @@
38893889
"ID": 322,
38903890
"Title": "Coin Change",
38913891
"TitleSlug": "coin-change",
3892-
"PassRate": "30%",
3892+
"PassRate": "31%",
38933893
"Difficulty": "Medium",
38943894
"IsAccepted": true,
38953895
"IsPaid": false,
@@ -5053,7 +5053,7 @@
50535053
"ID": 419,
50545054
"Title": "Battleships in a Board",
50555055
"TitleSlug": "battleships-in-a-board",
5056-
"PassRate": "65%",
5056+
"PassRate": "66%",
50575057
"Difficulty": "Medium",
50585058
"IsAccepted": true,
50595059
"IsPaid": false,
@@ -5341,7 +5341,7 @@
53415341
"ID": 443,
53425342
"Title": "String Compression",
53435343
"TitleSlug": "string-compression",
5344-
"PassRate": "37%",
5344+
"PassRate": "38%",
53455345
"Difficulty": "Easy",
53465346
"IsAccepted": true,
53475347
"IsPaid": false,
@@ -5761,7 +5761,7 @@
57615761
"ID": 478,
57625762
"Title": "Generate Random Point in a Circle",
57635763
"TitleSlug": "generate-random-point-in-a-circle",
5764-
"PassRate": "36%",
5764+
"PassRate": "37%",
57655765
"Difficulty": "Medium",
57665766
"IsAccepted": true,
57675767
"IsPaid": false,
@@ -9229,7 +9229,7 @@
92299229
"ID": 767,
92309230
"Title": "Reorganize String",
92319231
"TitleSlug": "reorganize-string",
9232-
"PassRate": "42%",
9232+
"PassRate": "43%",
92339233
"Difficulty": "Medium",
92349234
"IsAccepted": true,
92359235
"IsPaid": false,
@@ -10321,7 +10321,7 @@
1032110321
"ID": 858,
1032210322
"Title": "Mirror Reflection",
1032310323
"TitleSlug": "mirror-reflection",
10324-
"PassRate": "51%",
10324+
"PassRate": "52%",
1032510325
"Difficulty": "Medium",
1032610326
"IsAccepted": true,
1032710327
"IsPaid": false,
@@ -10573,7 +10573,7 @@
1057310573
"ID": 879,
1057410574
"Title": "Profitable Schemes",
1057510575
"TitleSlug": "profitable-schemes",
10576-
"PassRate": "36%",
10576+
"PassRate": "37%",
1057710577
"Difficulty": "Hard",
1057810578
"IsAccepted": true,
1057910579
"IsPaid": false,
@@ -11137,7 +11137,7 @@
1113711137
"ID": 926,
1113811138
"Title": "Flip String to Monotone Increasing",
1113911139
"TitleSlug": "flip-string-to-monotone-increasing",
11140-
"PassRate": "49%",
11140+
"PassRate": "50%",
1114111141
"Difficulty": "Medium",
1114211142
"IsAccepted": true,
1114311143
"IsPaid": false,
@@ -12013,7 +12013,7 @@
1201312013
"ID": 999,
1201412014
"Title": "Available Captures for Rook",
1201512015
"TitleSlug": "available-captures-for-rook",
12016-
"PassRate": "65%",
12016+
"PassRate": "66%",
1201712017
"Difficulty": "Easy",
1201812018
"IsAccepted": true,
1201912019
"IsPaid": false,
@@ -12121,7 +12121,7 @@
1212112121
"ID": 1008,
1212212122
"Title": "Construct Binary Search Tree from Preorder Traversal",
1212312123
"TitleSlug": "construct-binary-search-tree-from-preorder-traversal",
12124-
"PassRate": "72%",
12124+
"PassRate": "73%",
1212512125
"Difficulty": "Medium",
1212612126
"IsAccepted": true,
1212712127
"IsPaid": false,
@@ -13297,7 +13297,7 @@
1329713297
"ID": 1106,
1329813298
"Title": "Parsing A Boolean Expression",
1329913299
"TitleSlug": "parsing-a-boolean-expression",
13300-
"PassRate": "59%",
13300+
"PassRate": "58%",
1330113301
"Difficulty": "Hard",
1330213302
"IsAccepted": false,
1330313303
"IsPaid": false,
@@ -13321,7 +13321,7 @@
1332113321
"ID": 1108,
1332213322
"Title": "Defanging an IP Address",
1332313323
"TitleSlug": "defanging-an-ip-address",
13324-
"PassRate": "88%",
13324+
"PassRate": "87%",
1332513325
"Difficulty": "Easy",
1332613326
"IsAccepted": true,
1332713327
"IsPaid": false,
@@ -13357,7 +13357,7 @@
1335713357
"ID": 1111,
1335813358
"Title": "Maximum Nesting Depth of Two Valid Parentheses Strings",
1335913359
"TitleSlug": "maximum-nesting-depth-of-two-valid-parentheses-strings",
13360-
"PassRate": "62%",
13360+
"PassRate": "63%",
1336113361
"Difficulty": "Medium",
1336213362
"IsAccepted": false,
1336313363
"IsPaid": false,
@@ -13453,7 +13453,7 @@
1345313453
"ID": 1119,
1345413454
"Title": "Remove Vowels from a String",
1345513455
"TitleSlug": "remove-vowels-from-a-string",
13456-
"PassRate": "90%",
13456+
"PassRate": "91%",
1345713457
"Difficulty": "Easy",
1345813458
"IsAccepted": false,
1345913459
"IsPaid": true,
@@ -13465,7 +13465,7 @@
1346513465
"ID": 1120,
1346613466
"Title": "Maximum Average Subtree",
1346713467
"TitleSlug": "maximum-average-subtree",
13468-
"PassRate": "60%",
13468+
"PassRate": "61%",
1346913469
"Difficulty": "Medium",
1347013470
"IsAccepted": false,
1347113471
"IsPaid": true,
@@ -13477,7 +13477,7 @@
1347713477
"ID": 1121,
1347813478
"Title": "Divide Array Into Increasing Sequences",
1347913479
"TitleSlug": "divide-array-into-increasing-sequences",
13480-
"PassRate": "49%",
13480+
"PassRate": "50%",
1348113481
"Difficulty": "Hard",
1348213482
"IsAccepted": false,
1348313483
"IsPaid": true,
@@ -13489,7 +13489,7 @@
1348913489
"ID": 1122,
1349013490
"Title": "Relative Sort Array",
1349113491
"TitleSlug": "relative-sort-array",
13492-
"PassRate": "68%",
13492+
"PassRate": "69%",
1349313493
"Difficulty": "Easy",
1349413494
"IsAccepted": false,
1349513495
"IsPaid": false,
@@ -13501,7 +13501,7 @@
1350113501
"ID": 1123,
1350213502
"Title": "Lowest Common Ancestor of Deepest Leaves",
1350313503
"TitleSlug": "lowest-common-ancestor-of-deepest-leaves",
13504-
"PassRate": "63%",
13504+
"PassRate": "64%",
1350513505
"Difficulty": "Medium",
1350613506
"IsAccepted": false,
1350713507
"IsPaid": false,
@@ -13513,7 +13513,7 @@
1351313513
"ID": 1124,
1351413514
"Title": "Longest Well-Performing Interval",
1351513515
"TitleSlug": "longest-well-performing-interval",
13516-
"PassRate": "21%",
13516+
"PassRate": "25%",
1351713517
"Difficulty": "Medium",
1351813518
"IsAccepted": false,
1351913519
"IsPaid": false,
@@ -13525,7 +13525,7 @@
1352513525
"ID": 1125,
1352613526
"Title": "Smallest Sufficient Team",
1352713527
"TitleSlug": "smallest-sufficient-team",
13528-
"PassRate": "33%",
13528+
"PassRate": "40%",
1352913529
"Difficulty": "Hard",
1353013530
"IsAccepted": false,
1353113531
"IsPaid": false,

0 commit comments

Comments
 (0)