Skip to content

Commit 3cd46fe

Browse files
committed
test: 19 cases run parallel
1 parent 89dfdc4 commit 3cd46fe

File tree

20 files changed

+300
-203
lines changed

20 files changed

+300
-203
lines changed

README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,25 @@
5555
|22|[Generate Parentheses][Solutions-22]|[WindomZ][Solutions-22-Go]|Medium|[340 ns/op/4 test cases][Solutions-22-Test]|13 ms|
5656
|21|[Merge Two Sorted Lists][Solutions-21]|[WindomZ][Solutions-21-Go]|Easy|[89.0 ns/op/3 test cases][Solutions-21-Test]|3 ms|
5757
|20|[Valid Parentheses][Solutions-20]|[WindomZ][Solutions-20-Go]|Easy|[28.9 ns/op/6 test cases][Solutions-20-Test]|0 ms|
58-
|19|[Remove Nth Node From End of List][Solutions-19]|[WindomZ][Solutions-19-Go]|Medium|[0.00 ns/op/6 test cases][Solutions-19-Test]|3 ms|
59-
|18|[4Sum][Solutions-18]|[WindomZ][Solutions-18-Go]|Medium|[796 ns/op/3 test cases][Solutions-18-Test]|16 ms|
60-
|17|[Letter Combinations of a Phone Number][Solutions-17]|[WindomZ][Solutions-17-Go]|Medium|[1466 ns/op/4 test cases][Solutions-17-Test]|0 ms|
61-
|16|[3Sum Closest][Solutions-16]|[WindomZ][Solutions-16-Go]|Medium|[1426 ns/op/8 test cases][Solutions-16-Test]|9 ms|
62-
|15|[3Sum][Solutions-15]|[WindomZ][Solutions-15-Go]|Medium|[614 ns/op/4 test cases][Solutions-15-Test]|1525 ms|
63-
|14|[Longest Common Prefix][Solutions-14]|[WindomZ][Solutions-14-Go]|Easy|[45.8 ns/op/8 test cases][Solutions-14-Test]|3 ms|
64-
|13|[Roman to Integer][Solutions-13]|[WindomZ][Solutions-13-Go]|Easy|[101 ns/op/8 test cases][Solutions-13-Test]|19 ms|
65-
|12|[Integer to Roman][Solutions-12]|[WindomZ][Solutions-12-Go]|Medium|[96.6 ns/op/8 test cases][Solutions-12-Test]|22 ms|
66-
|11|[Container With Most Water][Solutions-11]|[WindomZ][Solutions-11-Go]|Medium|[38.0 ns/op/5 test cases][Solutions-11-Test]|25 ms|
67-
|10|[Regular Expression Matching][Solutions-10]|[WindomZ][Solutions-10-Go]|Hard|[630 ns/op/6 test cases][Solutions-10-Test]|3 ms|
68-
|9|[Palindrome Number][Solutions-9]|[WindomZ][Solutions-9-Go]|Easy|[27.3 ns/op/7 test cases][Solutions-9-Test]|55 ms|
69-
|8|[String to Integer (atoi)][Solutions-8]|[WindomZ][Solutions-8-Go]|Medium|[33.4 ns/op/5 test cases][Solutions-8-Test]|3 ms|
70-
|7|[Reverse Integer][Solutions-7]|[WindomZ][Solutions-7-Go]|Easy|[39.3 ns/op/5 test cases][Solutions-7-Test]|3 ms|
71-
|6|[ZigZag Conversion][Solutions-6]|[WindomZ][Solutions-6-Go]|Medium|[205 ns/op/5 test cases][Solutions-6-Test]|9 ms|
72-
|5|[Longest Palindromic Substring][Solutions-5]|[WindomZ][Solutions-5-Go]|Medium|[151 ns/op/6 test cases][Solutions-5-Test]|9 ms|
73-
|4|[Median of Two Sorted Arrays][Solutions-4]|[WindomZ][Solutions-4-Go]|Hard|[74.3 ns/op/14 test cases][Solutions-4-Test]|32 ms|
74-
|3|[Longest Substring Without Repeating Characters][Solutions-3]|[WindomZ][Solutions-3-Go]|Medium|[103 ns/op/3 test cases][Solutions-3-Test]|6 ms|
75-
|2|[Add Two Numbers][Solutions-2]|[WindomZ][Solutions-2-Go]|Medium|[79.4 ns/op/1 test cases][Solutions-2-Test]|29 ms|
76-
|1|[Two Sum][Solutions-1]|[WindomZ][Solutions-1-Go]|Easy|[305 ns/op/3 test cases][Solutions-1-Test]|6 ms|
58+
|19|[Remove Nth Node From End of List][Solutions-19]|[WindomZ][Solutions-19-Go]|Medium|[97.3 ns/op/6 test cases][Solutions-19-Test]|3 ms|
59+
|18|[4Sum][Solutions-18]|[WindomZ][Solutions-18-Go]|Medium|[233 ns/op/3 test cases][Solutions-18-Test]|16 ms|
60+
|17|[Letter Combinations of a Phone Number][Solutions-17]|[WindomZ][Solutions-17-Go]|Medium|[407 ns/op/4 test cases][Solutions-17-Test]|0 ms|
61+
|16|[3Sum Closest][Solutions-16]|[WindomZ][Solutions-16-Go]|Medium|[379 ns/op/8 test cases][Solutions-16-Test]|9 ms|
62+
|15|[3Sum][Solutions-15]|[WindomZ][Solutions-15-Go]|Medium|[183 ns/op/4 test cases][Solutions-15-Test]|1525 ms|
63+
|14|[Longest Common Prefix][Solutions-14]|[WindomZ][Solutions-14-Go]|Easy|[10.6 ns/op/8 test cases][Solutions-14-Test]|3 ms|
64+
|13|[Roman to Integer][Solutions-13]|[WindomZ][Solutions-13-Go]|Easy|[16.9 ns/op/8 test cases][Solutions-13-Test]|19 ms|
65+
|12|[Integer to Roman][Solutions-12]|[WindomZ][Solutions-12-Go]|Medium|[26.4 ns/op/8 test cases][Solutions-12-Test]|22 ms|
66+
|11|[Container With Most Water][Solutions-11]|[WindomZ][Solutions-11-Go]|Medium|[7.84 ns/op/5 test cases][Solutions-11-Test]|25 ms|
67+
|10|[Regular Expression Matching][Solutions-10]|[WindomZ][Solutions-10-Go]|Hard|[183 ns/op/6 test cases][Solutions-10-Test]|3 ms|
68+
|9|[Palindrome Number][Solutions-9]|[WindomZ][Solutions-9-Go]|Easy|[6.37 ns/op/7 test cases][Solutions-9-Test]|55 ms|
69+
|8|[String to Integer (atoi)][Solutions-8]|[WindomZ][Solutions-8-Go]|Medium|[7.31 ns/op/5 test cases][Solutions-8-Test]|3 ms|
70+
|7|[Reverse Integer][Solutions-7]|[WindomZ][Solutions-7-Go]|Easy|[9.00 ns/op/5 test cases][Solutions-7-Test]|3 ms|
71+
|6|[ZigZag Conversion][Solutions-6]|[WindomZ][Solutions-6-Go]|Medium|[55.1 ns/op/5 test cases][Solutions-6-Test]|9 ms|
72+
|5|[Longest Palindromic Substring][Solutions-5]|[WindomZ][Solutions-5-Go]|Medium|[39.1 ns/op/6 test cases][Solutions-5-Test]|9 ms|
73+
|4|[Median of Two Sorted Arrays][Solutions-4]|[WindomZ][Solutions-4-Go]|Hard|[19.4 ns/op/14 test cases][Solutions-4-Test]|32 ms|
74+
|3|[Longest Substring Without Repeating Characters][Solutions-3]|[WindomZ][Solutions-3-Go]|Medium|[21.3 ns/op/3 test cases][Solutions-3-Test]|6 ms|
75+
|2|[Add Two Numbers][Solutions-2]|[WindomZ][Solutions-2-Go]|Medium|[19.4 ns/op/1 test cases][Solutions-2-Test]|29 ms|
76+
|1|[Two Sum][Solutions-1]|[WindomZ][Solutions-1-Go]|Easy|[79.5 ns/op/3 test cases][Solutions-1-Test]|6 ms|
7777

7878
> **NOTE**: 'Single Repetition Duration' and 'LeetCode Run Time' are for _reference_ only.
7979

solutions/3sum/threeSum_test.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ func Test_threeSum(t *testing.T) {
1818
}
1919

2020
func Benchmark_threeSum(b *testing.B) {
21-
for i := 0; i < b.N; i++ {
22-
threeSum([]int{})
23-
threeSum([]int{1, 3, -4})
24-
threeSum([]int{0, 0, 0, 0})
25-
threeSum([]int{-1, 0, 1, 2, -1, -4})
26-
}
21+
b.StopTimer()
22+
b.ReportAllocs()
23+
b.StartTimer()
24+
b.RunParallel(func(pb *testing.PB) {
25+
for pb.Next() {
26+
threeSum([]int{})
27+
threeSum([]int{1, 3, -4})
28+
threeSum([]int{0, 0, 0, 0})
29+
threeSum([]int{-1, 0, 1, 2, -1, -4})
30+
}
31+
})
2732
}

solutions/3sum_closest/threeSumClosest_test.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ func Test_threeSumClosest(t *testing.T) {
1818
}
1919

2020
func Benchmark_threeSumClosest(b *testing.B) {
21-
for i := 0; i < b.N; i++ {
22-
threeSumClosest([]int{}, 0)
23-
threeSumClosest([]int{0, 0, 0}, 1)
24-
threeSumClosest([]int{-1, 2, 1, -4}, 5)
25-
threeSumClosest([]int{-1, 2, 1, -4, 5, 8}, -5)
26-
threeSumClosest([]int{-1, 2, 1, -4, 5, -8, 9}, 11)
27-
threeSumClosest([]int{-1, 2, 1, -4, 2, -8, 9, 10, 9}, 25)
28-
threeSumClosest([]int{-1, 2, 1, -4, 5, -8, -7, 9, 10, 9}, -20)
29-
threeSumClosest([]int{-55, -24, -18, -11, -7, -3, 4, 5, 6, 9, 11, 23, 33}, 0)
30-
}
21+
b.StopTimer()
22+
b.ReportAllocs()
23+
b.StartTimer()
24+
b.RunParallel(func(pb *testing.PB) {
25+
for pb.Next() {
26+
threeSumClosest([]int{}, 0)
27+
threeSumClosest([]int{0, 0, 0}, 1)
28+
threeSumClosest([]int{-1, 2, 1, -4}, 5)
29+
threeSumClosest([]int{-1, 2, 1, -4, 5, 8}, -5)
30+
threeSumClosest([]int{-1, 2, 1, -4, 5, -8, 9}, 11)
31+
threeSumClosest([]int{-1, 2, 1, -4, 2, -8, 9, 10, 9}, 25)
32+
threeSumClosest([]int{-1, 2, 1, -4, 5, -8, -7, 9, 10, 9}, -20)
33+
threeSumClosest([]int{-55, -24, -18, -11, -7, -3, 4, 5, 6, 9, 11, 23, 33}, 0)
34+
}
35+
})
3136
}

solutions/4sum/fourSum_test.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ func Test_fourSum(t *testing.T) {
2626
}
2727

2828
func Benchmark_fourSum(b *testing.B) {
29-
for i := 0; i < b.N; i++ {
30-
fourSum([]int{}, 0)
31-
fourSum([]int{1, 0, -1, 0, -2, 2}, 0)
32-
fourSum([]int{1, 0, -1, 0, -2, 2, -3, 3}, 0)
33-
}
29+
b.StopTimer()
30+
b.ReportAllocs()
31+
b.StartTimer()
32+
b.RunParallel(func(pb *testing.PB) {
33+
for pb.Next() {
34+
fourSum([]int{}, 0)
35+
fourSum([]int{1, 0, -1, 0, -2, 2}, 0)
36+
fourSum([]int{1, 0, -1, 0, -2, 2, -3, 3}, 0)
37+
}
38+
})
3439
}

solutions/add_two_numbers/addTwoNumbers_test.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ func Benchmark_addTwoNumbers(b *testing.B) {
134134
},
135135
},
136136
}
137-
for i := 0; i < b.N; i++ {
138-
addTwoNumbers(l1, l2)
139-
}
137+
b.StopTimer()
138+
b.ReportAllocs()
139+
b.StartTimer()
140+
b.RunParallel(func(pb *testing.PB) {
141+
for pb.Next() {
142+
addTwoNumbers(l1, l2)
143+
}
144+
})
140145
}

solutions/container_with_most_water/maxArea_test.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ func Test_maxArea(t *testing.T) {
1919
}
2020

2121
func Benchmark_maxArea(b *testing.B) {
22-
for i := 0; i < b.N; i++ {
23-
maxArea([]int{})
24-
maxArea([]int{1, 2, 3})
25-
maxArea([]int{5, 4, 3, 2, 1})
26-
maxArea([]int{1, 2, 3, 4, 5, 6, 7})
27-
maxArea([]int{8, 1, 7, 2, 6, 3, 5, 4})
28-
}
22+
b.StopTimer()
23+
b.ReportAllocs()
24+
b.StartTimer()
25+
b.RunParallel(func(pb *testing.PB) {
26+
for pb.Next() {
27+
maxArea([]int{})
28+
maxArea([]int{1, 2, 3})
29+
maxArea([]int{5, 4, 3, 2, 1})
30+
maxArea([]int{1, 2, 3, 4, 5, 6, 7})
31+
maxArea([]int{8, 1, 7, 2, 6, 3, 5, 4})
32+
}
33+
})
2934
}

solutions/integer_to_roman/intToRoman_test.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ func Test_intToRoman(t *testing.T) {
2020
}
2121

2222
func Benchmark_intToRoman(b *testing.B) {
23-
for i := 0; i < b.N; i++ {
24-
intToRoman(0)
25-
intToRoman(9)
26-
intToRoman(10)
27-
intToRoman(99)
28-
intToRoman(100)
29-
intToRoman(999)
30-
intToRoman(1000)
31-
intToRoman(3999)
32-
}
23+
b.StopTimer()
24+
b.ReportAllocs()
25+
b.StartTimer()
26+
b.RunParallel(func(pb *testing.PB) {
27+
for pb.Next() {
28+
intToRoman(0)
29+
intToRoman(9)
30+
intToRoman(10)
31+
intToRoman(99)
32+
intToRoman(100)
33+
intToRoman(999)
34+
intToRoman(1000)
35+
intToRoman(3999)
36+
}
37+
})
3338
}

solutions/letter_combinations_of_a_phone_number/letterCombinations_test.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ func Test_letterCombinations(t *testing.T) {
2525
}
2626

2727
func Benchmark_letterCombinations(b *testing.B) {
28-
for i := 0; i < b.N; i++ {
29-
letterCombinations("")
30-
letterCombinations("01")
31-
letterCombinations("24")
32-
letterCombinations("159")
33-
}
28+
b.StopTimer()
29+
b.ReportAllocs()
30+
b.StartTimer()
31+
b.RunParallel(func(pb *testing.PB) {
32+
for pb.Next() {
33+
letterCombinations("")
34+
letterCombinations("01")
35+
letterCombinations("24")
36+
letterCombinations("159")
37+
}
38+
})
3439
}

solutions/longest_common_prefix/longestCommonPrefix_test.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ func Test_longestCommonPrefix(t *testing.T) {
1717
}
1818

1919
func Benchmark_longestCommonPrefix(b *testing.B) {
20-
for i := 0; i < b.N; i++ {
21-
longestCommonPrefix([]string{})
22-
longestCommonPrefix([]string{"", "acb"})
23-
longestCommonPrefix([]string{"abc", "cba"})
24-
longestCommonPrefix([]string{"abc", "acb"})
25-
longestCommonPrefix([]string{"abc", "abd"})
26-
longestCommonPrefix([]string{"abcd", "abce", "abde"})
27-
longestCommonPrefix([]string{"abcd", "abce", "bdea", "abde"})
28-
longestCommonPrefix([]string{"abcd", "abcde", "abcdef", "abcefg"})
29-
}
20+
b.StopTimer()
21+
b.ReportAllocs()
22+
b.StartTimer()
23+
b.RunParallel(func(pb *testing.PB) {
24+
for pb.Next() {
25+
longestCommonPrefix([]string{})
26+
longestCommonPrefix([]string{"", "acb"})
27+
longestCommonPrefix([]string{"abc", "cba"})
28+
longestCommonPrefix([]string{"abc", "acb"})
29+
longestCommonPrefix([]string{"abc", "abd"})
30+
longestCommonPrefix([]string{"abcd", "abce", "abde"})
31+
longestCommonPrefix([]string{"abcd", "abce", "bdea", "abde"})
32+
longestCommonPrefix([]string{"abcd", "abcde", "abcdef", "abcefg"})
33+
}
34+
})
3035
}

solutions/longest_palindromic_substring/longestPalindrome_test.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ func Test_longestPalindrome(t *testing.T) {
1616
}
1717

1818
func Benchmark_longestPalindrome(b *testing.B) {
19-
for i := 0; i < b.N; i++ {
20-
longestPalindrome("")
21-
longestPalindrome("a")
22-
longestPalindrome("abcda")
23-
longestPalindrome("babad")
24-
longestPalindrome("cbbd")
25-
longestPalindrome("abacdfgdcaba")
26-
}
19+
b.StopTimer()
20+
b.ReportAllocs()
21+
b.StartTimer()
22+
b.RunParallel(func(pb *testing.PB) {
23+
for pb.Next() {
24+
longestPalindrome("")
25+
longestPalindrome("a")
26+
longestPalindrome("abcda")
27+
longestPalindrome("babad")
28+
longestPalindrome("cbbd")
29+
longestPalindrome("abacdfgdcaba")
30+
}
31+
})
2732
}

solutions/longest_substring_without_repeating_characters/lengthOfLongestSubstring_test.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ func Test_lengthOfLongestSubstring(t *testing.T) {
1414
}
1515

1616
func Benchmark_lengthOfLongestSubstring(b *testing.B) {
17-
for i := 0; i < b.N; i++ {
18-
lengthOfLongestSubstring("abcabcbb")
19-
lengthOfLongestSubstring("bbbbb")
20-
lengthOfLongestSubstring("pwwkew")
21-
}
17+
b.StopTimer()
18+
b.ReportAllocs()
19+
b.StartTimer()
20+
b.RunParallel(func(pb *testing.PB) {
21+
for pb.Next() {
22+
lengthOfLongestSubstring("abcabcbb")
23+
lengthOfLongestSubstring("bbbbb")
24+
lengthOfLongestSubstring("pwwkew")
25+
}
26+
})
2227
}

solutions/median_of_two_sorted_arrays/findMedianSortedArrays_test.go

+21-16
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,25 @@ func Test_findMedianSortedArrays(t *testing.T) {
6969
}
7070

7171
func Benchmark_findMedianSortedArrays(b *testing.B) {
72-
for i := 0; i < b.N; i++ {
73-
findMedianSortedArrays([]int{1}, []int{2, 3, 4})
74-
findMedianSortedArrays([]int{2}, []int{1, 3, 4})
75-
findMedianSortedArrays([]int{3}, []int{1, 2, 4})
76-
findMedianSortedArrays([]int{4}, []int{1, 2, 3})
77-
findMedianSortedArrays([]int{1, 2}, []int{3, 4})
78-
findMedianSortedArrays([]int{1, 3}, []int{2, 4})
79-
findMedianSortedArrays([]int{1, 4}, []int{2, 3})
80-
findMedianSortedArrays([]int{2, 3}, []int{1, 4})
81-
findMedianSortedArrays([]int{2, 4}, []int{1, 3})
82-
findMedianSortedArrays([]int{3, 4}, []int{1, 2})
83-
findMedianSortedArrays([]int{1, 2, 3}, []int{4})
84-
findMedianSortedArrays([]int{1, 2, 4}, []int{3})
85-
findMedianSortedArrays([]int{1, 3, 4}, []int{2})
86-
findMedianSortedArrays([]int{2, 3, 4}, []int{1})
87-
}
72+
b.StopTimer()
73+
b.ReportAllocs()
74+
b.StartTimer()
75+
b.RunParallel(func(pb *testing.PB) {
76+
for pb.Next() {
77+
findMedianSortedArrays([]int{1}, []int{2, 3, 4})
78+
findMedianSortedArrays([]int{2}, []int{1, 3, 4})
79+
findMedianSortedArrays([]int{3}, []int{1, 2, 4})
80+
findMedianSortedArrays([]int{4}, []int{1, 2, 3})
81+
findMedianSortedArrays([]int{1, 2}, []int{3, 4})
82+
findMedianSortedArrays([]int{1, 3}, []int{2, 4})
83+
findMedianSortedArrays([]int{1, 4}, []int{2, 3})
84+
findMedianSortedArrays([]int{2, 3}, []int{1, 4})
85+
findMedianSortedArrays([]int{2, 4}, []int{1, 3})
86+
findMedianSortedArrays([]int{3, 4}, []int{1, 2})
87+
findMedianSortedArrays([]int{1, 2, 3}, []int{4})
88+
findMedianSortedArrays([]int{1, 2, 4}, []int{3})
89+
findMedianSortedArrays([]int{1, 3, 4}, []int{2})
90+
findMedianSortedArrays([]int{2, 3, 4}, []int{1})
91+
}
92+
})
8893
}

solutions/palindrome_number/isPalindrome_test.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ func Test_isPalindrome(t *testing.T) {
1818
}
1919

2020
func Benchmark_isPalindrome(b *testing.B) {
21-
for i := 0; i < b.N; i++ {
22-
isPalindrome(-1)
23-
isPalindrome(5)
24-
isPalindrome(10)
25-
isPalindrome(121)
26-
isPalindrome(1210)
27-
isPalindrome(123454321)
28-
isPalindrome(123456764321)
29-
}
21+
b.StopTimer()
22+
b.ReportAllocs()
23+
b.StartTimer()
24+
b.RunParallel(func(pb *testing.PB) {
25+
for pb.Next() {
26+
isPalindrome(-1)
27+
isPalindrome(5)
28+
isPalindrome(10)
29+
isPalindrome(121)
30+
isPalindrome(1210)
31+
isPalindrome(123454321)
32+
isPalindrome(123456764321)
33+
}
34+
})
3035
}

solutions/regular_expression_matching/isMatch_test.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ func Test_isMatch(t *testing.T) {
3838
}
3939

4040
func Benchmark_isMatch(b *testing.B) {
41-
for i := 0; i < b.N; i++ {
42-
isMatch("", "")
43-
isMatch("aa", "aa")
44-
isMatch("aa", "a.")
45-
isMatch("ab", ".*")
46-
isMatch("aab", "c*a*b")
47-
isMatch("acdefgb", "a.*b")
48-
}
41+
b.StopTimer()
42+
b.ReportAllocs()
43+
b.StartTimer()
44+
b.RunParallel(func(pb *testing.PB) {
45+
for pb.Next() {
46+
isMatch("", "")
47+
isMatch("aa", "aa")
48+
isMatch("aa", "a.")
49+
isMatch("ab", ".*")
50+
isMatch("aab", "c*a*b")
51+
isMatch("acdefgb", "a.*b")
52+
}
53+
})
4954
}

0 commit comments

Comments
 (0)