Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc3ab7ec

Browse files
authored
Merge pull request6boris#221 from kylesliu/develop
add some solution
2 parents993d72e +31bd133 commitc3ab7ec

File tree

4 files changed

+74
-10
lines changed

4 files changed

+74
-10
lines changed

‎lcof/of024/Solution.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ func reverseList(head *ListNode) *ListNode {
1515
returnnewHead
1616
}
1717

18-
//funcreverseList2(head *ListNode) *ListNode {
19-
//varpre *ListNode
20-
//var next *ListNode
21-
//forhead != nil {
22-
//next= head.Next
23-
//head.Next =pre
24-
//pre =head
25-
//head = next
18+
//funcreverseList_2(head *ListNode) *ListNode {
19+
//varprev *ListNode
20+
//curr := head
21+
//forcurr != nil {
22+
//next:= curr.Next
23+
//curr.Next =prev
24+
//prev =curr
25+
//curr = next
2626
//}
27-
//returnpre
27+
//returnprev
2828
//}
2929

30-
//funcreverseList3(head *ListNode) *ListNode {
30+
//funcreverseList_3(head *ListNode) *ListNode {
3131
//var prev *ListNode
3232
//
3333
//for head != nil {

‎lcof/of024/Solution_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type SolutionFuncType func(*ListNode) *ListNode
1313

1414
varSolutionFuncList= []SolutionFuncType{
1515
reverseList,
16+
//reverseList_2,
17+
//reverseList_3,
1618
}
1719

1820
//test info struct

‎lcof/of040/Solution.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package Solution
2+
3+
import (
4+
"sort"
5+
)
6+
7+
funcgetLeastNumbers(arr []int,kint) []int {
8+
ans:=make([]int,k)
9+
sort.Ints(arr)
10+
fori:=0;i<k;i++ {
11+
ans[i]=arr[i]
12+
}
13+
returnans
14+
}

‎lcof/of040/Solution_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package Solution
2+
3+
import (
4+
"fmt"
5+
"reflect"
6+
"runtime"
7+
"strings"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
//solution func Info
14+
typeSolutionFuncTypefunc([]int,int) []int
15+
16+
varSolutionFuncList= []SolutionFuncType{
17+
getLeastNumbers,
18+
}
19+
20+
//test info struct
21+
typeCasestruct {
22+
namestring
23+
arr []int
24+
kint
25+
expect []int
26+
}
27+
28+
// Test case
29+
varcases= []Case{
30+
{name:"TestCase",arr: []int{3,2,1},k:2,expect: []int{1,2}},
31+
{name:"TestCase",arr: []int{0,1,2,1},k:1,expect: []int{0}},
32+
}
33+
34+
// TestSolution Example for solution test cases
35+
funcTestSolution(t*testing.T) {
36+
ast:=assert.New(t)
37+
38+
for_,f:=rangeSolutionFuncList {
39+
funcName:=strings.Split(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(),".")[1]
40+
for_,c:=rangecases {
41+
t.Run(fmt.Sprintf("%s %s",funcName,c.name),func(t*testing.T) {
42+
got:=f(c.arr,c.k)
43+
ast.Equal(c.expect,got,
44+
"func: %v case: %v ",funcName,c.name)
45+
})
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp