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

Commit30724b7

Browse files
author
Kyle Liu
authored
Merge pull request6boris#144 from sathishbabu96/master
New test cases and solutions
2 parentse9eba16 +f099aa0 commit30724b7

File tree

99 files changed

+1461
-282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1461
-282
lines changed

‎src/0118.Pascals-Triangle/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88
**Example 1:**
99

1010
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
11+
Input: 5
12+
Output:
13+
[
14+
[1],
15+
[1,1],
16+
[1,2,1],
17+
[1,3,3,1],
18+
[1,4,6,4,1]
19+
]
20+
1321
```
1422

1523
##题意

‎src/0118.Pascals-Triangle/Solution.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package Solution
22

3-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(numRowsint) [][]int {
4+
pt:=make([][]int,numRows)
5+
fori:=rangept {
6+
pt[i]=make([]int,i+1)
7+
}
8+
fori,val:=rangept {
9+
pt[i][0],pt[i][len(val)-1]=1,1
10+
}
11+
fori:=1;i<numRows-1;i++ {
12+
forj:=0;j<len(pt[i])-1;j++ {
13+
pt[i+1][j+1]=pt[i][j]+pt[i][j+1]
14+
}
15+
}
16+
returnpt
517
}

‎src/0118.Pascals-Triangle/Solution_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
//测试用例
1111
cases:= []struct {
1212
namestring
13-
inputsbool
14-
expectbool
13+
inputsint
14+
expect[][]int
1515
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
16+
{"TestCase",5, [][]int{{1}, {1,1}, {1,2,1}, {1,3,3,1}, {1,4,6,4,1}}},
17+
{"TestCase",2, [][]int{{1}, {1,1}}},
1918
}
2019

2120
//开始测试

‎src/0122.Best-Time-To-Buy-And-Sell-Stock-II/Solution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func maxProfit(prices []int) int {
2424
//dp[i][0] means the maximum profit after sunset of day i with no stock in hand
2525
//dp[i][1] means the maximum profit after sunset of day i with stock in hand
2626
//dp[i][0] = max(dp[i-1][1]+price[i],dp[i-1][0]) --> Sell on day i or do nothing
27-
//dp[i][1] = max(dp[i-1][0])-price[i],dp[i-1][1]) --> Buy on day i or do nothing
27+
//dp[i][1] = max(dp[i-1][0]-price[i],dp[i-1][1]) --> Buy on day i or do nothing
2828
//dp[0][0]=0,dp[0][1]=INT_MIN
2929

3030
funcmaxProfit2(prices []int)int {

‎src/0167.Two-Sum-II--Input-array-is-sorted/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
**Example 1:**
99

1010
```
11-
Input:a ="11", b ="1"
12-
Output:"100"
11+
Input:numbers =[2,7,11,15], target =9
12+
Output:[1,2]
1313
```
1414

1515
##题意
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
package Solution
22

3-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(numbers []int,targetint) []int {
4+
i,j:=0,len(numbers)-1
5+
fori<j {
6+
sum:=numbers[i]+numbers[j]
7+
ifsum<target {
8+
i++
9+
}elseifsum>target {
10+
j--
11+
}else {
12+
return []int{i+1,j+1}
13+
}
14+
}
15+
return []int{0,0}
516
}

‎src/0167.Two-Sum-II--Input-array-is-sorted/Solution_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ import (
99
funcTestSolution(t*testing.T) {
1010
//测试用例
1111
cases:= []struct {
12-
namestring
13-
inputsbool
14-
expectbool
12+
namestring
13+
numbers []int
14+
targetint
15+
expect []int
1516
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
17+
{"TestCase",[]int{2,7,11,15},9, []int{1,2}},
18+
{"TestCase",[]int{2,7,11,15},22, []int{2,4}},
19+
{"TestCase",[]int{2,7,11,15},26, []int{3,4}},
1920
}
2021

2122
//开始测试
2223
fori,c:=rangecases {
2324
t.Run(c.name+" "+strconv.Itoa(i),func(t*testing.T) {
24-
got:=Solution(c.inputs)
25+
got:=Solution(c.numbers,c.target)
2526
if!reflect.DeepEqual(got,c.expect) {
26-
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
27-
c.expect,got,c.inputs)
27+
t.Fatalf("expected: %v, but got: %v, with inputs: %v %v",
28+
c.expect,got,c.numbers,c.target)
2829
}
2930
})
3031
}

‎src/0268.Missing-Number/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
**Example 1:**
99

1010
```
11-
Input:a = "11", b = "1"
12-
Output:"100"
11+
Input:[3,0,1]
12+
Output:2
1313
```
1414

1515
##题意

‎src/0268.Missing-Number/Solution.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package Solution
22

3-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(nums []int)int {
4+
ans:=len(nums)
5+
fori,num:=rangenums {
6+
ans^=i^num
7+
}
8+
returnans
59
}

‎src/0268.Missing-Number/Solution_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
//测试用例
1111
cases:= []struct {
1212
namestring
13-
inputsbool
14-
expectbool
13+
inputs[]int
14+
expectint
1515
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
16+
{"TestCase", []int{3,0,1},2},
17+
{"TestCase", []int{9,6,4,2,3,5,7,0,1},8},
1918
}
2019

2120
//开始测试

‎src/0283.Move-Zeroes/Solution.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,16 @@ func moveZeroes(nums []int) []int {
1414
}
1515
returnnums
1616
}
17+
18+
funcmoveZeroes2(nums []int) []int {
19+
n:=len(nums)
20+
ifn>1 {
21+
forz,nz:=0,0;nz<n;nz++ {
22+
ifnums[nz]!=0 {
23+
nums[z],nums[nz]=nums[nz],nums[z]
24+
z++
25+
}
26+
}
27+
}
28+
returnnums
29+
}

‎src/0283.Move-Zeroes/Solution_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package Solution
22

33
import (
44
"reflect"
5+
"strconv"
56
"testing"
67
)
78

@@ -24,3 +25,25 @@ func TestMoveZeroes(t *testing.T) {
2425
})
2526
}
2627
}
28+
29+
funcTestMoveZeroes2(t*testing.T) {
30+
cases:= []struct {
31+
namestring
32+
inputs []int
33+
expects []int
34+
}{
35+
{"TestCase", []int{0,1,0,3,12}, []int{1,3,12,0,0}},
36+
{"TestCase", []int{0}, []int{0}},
37+
{"TestCase", []int{1}, []int{1}},
38+
}
39+
40+
fori,testcase:=rangecases {
41+
t.Run(testcase.name+" "+strconv.Itoa(i),func(t*testing.T) {
42+
result:=moveZeroes2(testcase.inputs)
43+
if!reflect.DeepEqual(result,testcase.expects) {
44+
t.Fatalf("expected: %v, but got: %v, with input: %v ",testcase.expects,result,testcase.inputs)
45+
}
46+
47+
})
48+
}
49+
}

‎src/0509.Fibonacci-Number/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
**Example 1:**
99

1010
```
11-
Input:a = "11", b = "1"
12-
Output:"100"
11+
Input:2
12+
Output:1
1313
```
1414

1515
##题意

‎src/0509.Fibonacci-Number/Solution.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
package Solution
22

3-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(Nint)int {
4+
varansint
5+
fibSeq:=getFibSeq()
6+
fori:=0;i<=N;i++ {
7+
ans=fibSeq()
8+
}
9+
returnans
10+
}
11+
12+
funcgetFibSeq()func()int {
13+
a,b:=-1,1
14+
returnfunc()int {
15+
c:=a+b
16+
a,b=b,c
17+
returnc
18+
}
519
}

‎src/0509.Fibonacci-Number/Solution_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ func TestSolution(t *testing.T) {
1010
//测试用例
1111
cases:= []struct {
1212
namestring
13-
inputsbool
14-
expectbool
13+
inputsint
14+
expectint
1515
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
16+
{"TestCase",2,1},
17+
{"TestCase",3,2},
18+
{"TestCase",4,3},
19+
{"TestCase",0,0},
1920
}
2021

2122
//开始测试

‎src/0566.Reshape-the-Matrix/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
**Example 1:**
99

1010
```
11-
Input:a ="11", b = "1"
12-
Output:"100"
11+
Input:nums =[[1,2], [3,4]] r = 1, c = 4
12+
Output:[[1,2,3,4]]
1313
```
1414

1515
##题意
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
package Solution
22

3-
funcSolution(xbool)bool {
4-
returnx
3+
funcSolution(nums [][]int,rint,cint) [][]int {
4+
m,n:=len(nums),len(nums[0])
5+
ifm*n!=r*c {
6+
returnnums
7+
}
8+
newNums:=make([][]int,r)
9+
fori:=rangenewNums {
10+
newNums[i]=make([]int,c)
11+
}
12+
k:=0
13+
fori:=0;i<m;i++ {
14+
forj:=0;j<n;j++ {
15+
r_,c_:=k/c,k%c
16+
newNums[r_][c_]=nums[i][j]
17+
k++
18+
}
19+
}
20+
returnnewNums
521
}

‎src/0566.Reshape-the-Matrix/Solution_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ func TestSolution(t *testing.T) {
1010
//测试用例
1111
cases:= []struct {
1212
namestring
13-
inputsbool
14-
expectbool
13+
nums [][]int
14+
r,cint
15+
expect [][]int
1516
}{
16-
{"TestCase",true,true},
17-
{"TestCase",true,true},
18-
{"TestCase",false,false},
17+
{"TestCase", [][]int{{1,2}, {3,4}},1,4, [][]int{{1,2,3,4}}},
18+
{"TestCase", [][]int{{1,2}, {3,4}},2,4, [][]int{{1,2}, {3,4}}},
1919
}
2020

2121
//开始测试
2222
fori,c:=rangecases {
2323
t.Run(c.name+" "+strconv.Itoa(i),func(t*testing.T) {
24-
got:=Solution(c.inputs)
24+
got:=Solution(c.nums,c.r,c.c)
2525
if!reflect.DeepEqual(got,c.expect) {
26-
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
27-
c.expect,got,c.inputs)
26+
t.Fatalf("expected: %v, but got: %v, with inputs: %v %v %v",
27+
c.expect,got,c.nums,c.r,c.c)
2828
}
2929
})
3030
}

‎src/0661.Image-Smoother/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
**Example 1:**
99

1010
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
11+
Input:
12+
[[1,1,1],
13+
[1,0,1],
14+
[1,1,1]]
15+
Output:
16+
[[0, 0, 0],
17+
[0, 0, 0],
18+
[0, 0, 0]]
1319
```
1420

1521
##题意

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp