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

Commit 156c84a

Browse files
committed
912 accepted. 868ms
1 parent 314a27a commit 156c84a

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# [912. Sort an Array](https://leetcode.com/problems/sort-an-array/)
2+
3+
Given an array of integers nums, sort the array in ascending order.
4+
5+
Example 1:
6+
7+
```text
8+
Input: [5,2,3,1]
9+
Output: [1,2,3,5]
10+
```
11+
12+
Example 2:
13+
14+
```text
15+
Input: [5,1,1,2,0,0]
16+
Output: [0,0,1,1,2,5]
17+
```
18+
19+
Note:
20+
21+
- 1 <= A.length <= 10000
22+
- -50000 <= A[i] <= 50000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package problem0912
2+
3+
import "sort"
4+
5+
func sortArray(nums []int) []int {
6+
sort.Ints(nums)
7+
return nums
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package problem0912
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// tcs is testcase slice
10+
var tcs = []struct {
11+
nums []int
12+
ans []int
13+
}{
14+
15+
{
16+
[]int{5, 2, 3, 1},
17+
[]int{1, 2, 3, 5},
18+
},
19+
20+
{
21+
[]int{5, 1, 1, 2, 0, 0},
22+
[]int{0, 0, 1, 1, 2, 5},
23+
},
24+
25+
// 可以有多个 testcase
26+
}
27+
28+
func Test_sortArray(t *testing.T) {
29+
ast := assert.New(t)
30+
31+
for _, tc := range tcs {
32+
ast.Equal(tc.ans, sortArray(tc.nums), "输入:%v", tc)
33+
}
34+
}
35+
36+
func Benchmark_sortArray(b *testing.B) {
37+
for i := 0; i < b.N; i++ {
38+
for _, tc := range tcs {
39+
sortArray(tc.nums)
40+
}
41+
}
42+
}

leetcode.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 887,
4-
"Updated": "2019-05-19T13:23:04.806650088+08:00",
4+
"Updated": "2019-05-19T13:58:53.651574703+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 235,
88
"Total": 247
99
},
1010
"Medium": {
11-
"Solved": 376,
11+
"Solved": 377,
1212
"Total": 414
1313
},
1414
"Hard": {
1515
"Solved": 165,
1616
"Total": 177
1717
},
1818
"Total": {
19-
"Solved": 776,
19+
"Solved": 777,
2020
"Total": 838
2121
}
2222
},
@@ -4659,7 +4659,7 @@
46594659
"TitleSlug": "lexicographical-numbers",
46604660
"PassRate": "45%",
46614661
"Difficulty": "Medium",
4662-
"IsAccepted": false,
4662+
"IsAccepted": true,
46634663
"IsPaid": false,
46644664
"IsFavor": false,
46654665
"IsNew": false,
@@ -10825,7 +10825,7 @@
1082510825
"ID": 900,
1082610826
"Title": "RLE Iterator",
1082710827
"TitleSlug": "rle-iterator",
10828-
"PassRate": "49%",
10828+
"PassRate": "50%",
1082910829
"Difficulty": "Medium",
1083010830
"IsAccepted": true,
1083110831
"IsPaid": false,
@@ -11005,7 +11005,7 @@
1100511005
"ID": 915,
1100611006
"Title": "Partition Array into Disjoint Intervals",
1100711007
"TitleSlug": "partition-array-into-disjoint-intervals",
11008-
"PassRate": "43%",
11008+
"PassRate": "42%",
1100911009
"Difficulty": "Medium",
1101011010
"IsAccepted": true,
1101111011
"IsPaid": false,
@@ -12589,7 +12589,7 @@
1258912589
"ID": 1047,
1259012590
"Title": "Remove All Adjacent Duplicates In String",
1259112591
"TitleSlug": "remove-all-adjacent-duplicates-in-string",
12592-
"PassRate": "54%",
12592+
"PassRate": "55%",
1259312593
"Difficulty": "Easy",
1259412594
"IsAccepted": false,
1259512595
"IsPaid": false,
@@ -12601,7 +12601,7 @@
1260112601
"ID": 1048,
1260212602
"Title": "Longest String Chain",
1260312603
"TitleSlug": "longest-string-chain",
12604-
"PassRate": "37%",
12604+
"PassRate": "38%",
1260512605
"Difficulty": "Medium",
1260612606
"IsAccepted": false,
1260712607
"IsPaid": false,
@@ -12613,7 +12613,7 @@
1261312613
"ID": 1049,
1261412614
"Title": "Last Stone Weight II",
1261512615
"TitleSlug": "last-stone-weight-ii",
12616-
"PassRate": "18%",
12616+
"PassRate": "19%",
1261712617
"Difficulty": "Medium",
1261812618
"IsAccepted": false,
1261912619
"IsPaid": false,

0 commit comments

Comments
 (0)