Skip to content

Commit baa5d75

Browse files
committed
测试
1 parent ff104fb commit baa5d75

File tree

8 files changed

+166
-51
lines changed

8 files changed

+166
-51
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/a-number-after-a-double-reversal/
14+
1315
https://leetcode.cn/problems/minimum-time-difference/
1416

1517
https://leetcode.cn/problems/excel-sheet-column-title/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function isSameAfterReversals(num: number): boolean {
2+
return num == 0 || num % 10 > 0;
3+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package index
2+
3+
import (
4+
"testing"
5+
6+
"github.com/datreeio/datree/pkg/utils"
7+
"gotest.tools/v3/assert"
8+
)
9+
10+
func TestAbbreviateProduct(t *testing.T) {
11+
var input = [][]int{{1, 4}, {1000, 4000}, {2, 11}, {371, 375}, {10000, 10000}, {
12+
1,
13+
10000,
14+
}}
15+
var result []string = utils.MapSlice(input, func(a []int) string {
16+
return abbreviateProduct(a[0], a[1])
17+
})
18+
var expected = []string{
19+
"24e0",
20+
"45448...88768e753",
21+
"399168e2",
22+
"7219856259e3",
23+
"1e4",
24+
"28462...79008e2499",
25+
}
26+
assert.DeepEqual(t, expected, result)
27+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package index
2-
3-
func AbbreviateProduct(left, right int) string {
4-
5-
return abbreviateProduct(left, right)
6-
}
1+
package index
2+
3+
func AbbreviateProduct(left, right int) string {
4+
5+
return abbreviateProduct(left, right)
6+
}
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
module github.com/masx200/leetcode-test/abbreviating-the-product-of-a-range
1+
module github.com/masx200/leetcode-test/abbreviating-the-product-of-a-range
2+
3+
go 1.19
4+
5+
require (
6+
github.com/datreeio/datree v1.6.28
7+
gotest.tools/v3 v3.3.0
8+
)
9+
10+
require (
11+
github.com/go-ole/go-ole v1.2.6 // indirect
12+
github.com/google/go-cmp v0.5.7 // indirect
13+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
14+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
15+
github.com/shirou/gopsutil/v3 v3.22.2 // indirect
16+
github.com/tklauser/go-sysconf v0.3.9 // indirect
17+
github.com/tklauser/numcpus v0.3.0 // indirect
18+
github.com/yusufpapurcu/wmi v1.2.2 // indirect
19+
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
20+
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
github.com/datreeio/datree v1.6.28 h1:leN8E3lU3v4YukxxAa5w9EezwtN6IqRDQfeoMUHkiO0=
2+
github.com/datreeio/datree v1.6.28/go.mod h1:+v/rE2vx+dshduvk1Ne2imtuT5jP3pimW2o5ukmFEjo=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
6+
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
7+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
8+
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
9+
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
10+
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
11+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
12+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
16+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
17+
github.com/shirou/gopsutil/v3 v3.22.2 h1:wCrArWFkHYIdDxx/FSfF5RB4dpJYW6t7rcp3+zL8uks=
18+
github.com/shirou/gopsutil/v3 v3.22.2/go.mod h1:WapW1AOOPlHyXr+yOyw3uYx36enocrtSoSBy0L5vUHY=
19+
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
20+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
21+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
22+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
23+
github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo=
24+
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
25+
github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ=
26+
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
27+
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
28+
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
29+
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
30+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
31+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
32+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
33+
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
34+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
35+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
36+
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
37+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
38+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
39+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
40+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
41+
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
42+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
43+
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
44+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
45+
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
46+
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
47+
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e h1:NHvCuwuS43lGnYhten69ZWqi2QOj/CiDNcKbVqwVoew=
48+
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
49+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
50+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
51+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
52+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
53+
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
54+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
55+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
56+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
57+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
58+
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f h1:uF6paiQQebLeSXkrTqHqz0MXhXXS1KgF41eUdBNvxK0=
59+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
60+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
61+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
62+
gotest.tools/v3 v3.3.0 h1:MfDY1b1/0xN1CyMlQDac0ziEy9zJQd9CXBRRDHw2jJo=
63+
gotest.tools/v3 v3.3.0/go.mod h1:Mcr9QNxkg0uMvy/YElmo4SpXgJKWgQvYrT7Kw5RzJ1A=
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
package index
2-
3-
import (
4-
"fmt"
5-
"math/big"
6-
"strconv"
7-
"strings"
8-
)
9-
10-
var factorials = make([]*big.Int, 10001)
11-
12-
func initialization() {
13-
if factorials[0] == nil {
14-
var i int64 = 0
15-
for ; i <= 10000; i++ {
16-
if i == 0 {
17-
factorials[i] = big.NewInt(1)
18-
} else {
19-
factorials[i] = new(big.Int).Mul(factorials[i-1], big.NewInt(i))
20-
}
21-
22-
}
23-
}
24-
}
25-
26-
func abbreviateProduct(left, right int) string {
27-
initialization()
28-
var s string
29-
if left == right {
30-
s = strconv.Itoa(left)
31-
} else {
32-
s = new(big.Int).Div(factorials[right], factorials[left-1]).String()
33-
}
34-
tz := len(s)
35-
s = strings.TrimRight(s, "0")
36-
tz -= len(s)
37-
if len(s) > 10 {
38-
return fmt.Sprintf("%s...%se%d", s[:5], s[len(s)-5:], tz)
39-
}
40-
return fmt.Sprintf("%se%d", s, tz)
41-
}
1+
package index
2+
3+
import (
4+
"fmt"
5+
"math/big"
6+
"strconv"
7+
"strings"
8+
)
9+
10+
var factorials = make([]*big.Int, 10001)
11+
12+
func initialization() {
13+
if factorials[0] == nil {
14+
var i int64 = 0
15+
for ; i <= 10000; i++ {
16+
if i == 0 {
17+
factorials[i] = big.NewInt(1)
18+
} else {
19+
factorials[i] = new(big.Int).Mul(factorials[i-1], big.NewInt(i))
20+
}
21+
22+
}
23+
}
24+
}
25+
26+
func abbreviateProduct(left, right int) string {
27+
initialization()
28+
var s string
29+
if left == right {
30+
s = strconv.Itoa(left)
31+
} else {
32+
s = new(big.Int).Div(factorials[right], factorials[left-1]).String()
33+
}
34+
tz := len(s)
35+
s = strings.TrimRight(s, "0")
36+
tz -= len(s)
37+
if len(s) > 10 {
38+
return fmt.Sprintf("%s...%se%d", s[:5], s[len(s)-5:], tz)
39+
}
40+
return fmt.Sprintf("%se%d", s, tz)
41+
}

abbreviating-the-product-of-a-range/test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
22
import abbreviateProduct from "./index.ts";
3+
34
Deno.test("abbreviating-the-product-of-a-range", () => {
4-
const result = [[1, 4], [1000, 4000], [2, 11], [371, 375], [10000, 10000], [
5+
const input = [[1, 4], [1000, 4000], [2, 11], [371, 375], [10000, 10000], [
56
1,
67
10000,
7-
]].map((a) => abbreviateProduct(a[0], a[1]));
8+
]];
9+
const result = input.map((a) => abbreviateProduct(a[0], a[1]));
810
const expected = [
911
"24e0",
1012
"45448...88768e753",
@@ -13,7 +15,6 @@ Deno.test("abbreviating-the-product-of-a-range", () => {
1315
"1e4",
1416
"28462...79008e2499",
1517
];
16-
// console.log(result, expected);
1718
assertEquals(
1819
result,
1920
expected,

0 commit comments

Comments
 (0)