Skip to content

Commit beccf9f

Browse files
committed
更正路径
1 parent ef09a17 commit beccf9f

File tree

106 files changed

+302
-56
lines changed

Some content is hidden

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

106 files changed

+302
-56
lines changed

Algorithms/0055. Jump Game/55. Jump Game.go renamed to Algorithms/0055.Jump-Game/55. Jump Game.go

+7
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ func canJump(nums []int) bool {
1717
}
1818
return true
1919
}
20+
21+
func max(a int, b int) int {
22+
if a > b {
23+
return a
24+
}
25+
return b
26+
}

Algorithms/0337. House Robber III/337. House Robber III.go renamed to Algorithms/0337.House-Robber-III/337. House Robber III.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package leetcode
22

3+
import (
4+
"github.com/halfrost/LeetCode-Go/structures"
5+
)
6+
7+
// TreeNode define
8+
type TreeNode = structures.TreeNode
9+
310
/**
411
* Definition for a binary tree node.
512
* type TreeNode struct {
@@ -25,3 +32,10 @@ func dfsTreeRob(root *TreeNode) (a, b int) {
2532
tmp1 := root.Val + l0 + r0
2633
return tmp0, tmp1
2734
}
35+
36+
func max(a int, b int) int {
37+
if a > b {
38+
return a
39+
}
40+
return b
41+
}

Algorithms/0337. House Robber III/337. House Robber III_test.go renamed to Algorithms/0337.House-Robber-III/337. House Robber III_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package leetcode
33
import (
44
"fmt"
55
"testing"
6+
7+
"github.com/halfrost/LeetCode-Go/structures"
68
)
79

810
type question337 struct {
@@ -27,7 +29,7 @@ func Test_Problem337(t *testing.T) {
2729
qs := []question337{
2830

2931
question337{
30-
para337{[]int{3, 2, 3, NULL, 3, NULL, 1}},
32+
para337{[]int{3, 2, 3, structures.NULL, 3, structures.NULL, 1}},
3133
ans337{7},
3234
},
3335

@@ -37,7 +39,7 @@ func Test_Problem337(t *testing.T) {
3739
},
3840

3941
question337{
40-
para337{[]int{3, 4, 5, 1, 3, NULL, 1}},
42+
para337{[]int{3, 4, 5, 1, 3, structures.NULL, 1}},
4143
ans337{9},
4244
},
4345
}
@@ -46,7 +48,7 @@ func Test_Problem337(t *testing.T) {
4648

4749
for _, q := range qs {
4850
_, p := q.ans337, q.para337
49-
fmt.Printf("【input】:%v 【output】:%v\n", p, rob337(Ints2TreeNode(p.one)))
51+
fmt.Printf("【input】:%v 【output】:%v\n", p, rob337(structures.Ints2TreeNode(p.one)))
5052
}
5153
fmt.Printf("\n\n\n")
5254
}

Algorithms/0529. Minesweeper/529. Minesweeper.go renamed to Algorithms/0529.Minesweeper/529. Minesweeper.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func updateBoard(board [][]byte, click []int) [][]byte {
3939
return board
4040
}
4141

42+
func isInBoard(board [][]byte, x, y int) bool {
43+
return x >= 0 && x < len(board) && y >= 0 && y < len(board[0])
44+
}
45+
4246
func mineSweeper(x, y int, board [][]byte, mineMap [][]int, dir8 [][]int) {
4347
if board[x][y] != 'M' && board[x][y] != 'E' {
4448
return

Algorithms/0695. Max Area of Island/695. Max Area of Island.go renamed to Algorithms/0695.Max-Area-of-Island/695. Max Area of Island.go

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package leetcode
22

3+
var dir = [][]int{
4+
[]int{-1, 0},
5+
[]int{0, 1},
6+
[]int{1, 0},
7+
[]int{0, -1},
8+
}
9+
310
func maxAreaOfIsland(grid [][]int) int {
411
res := 0
512
for i, row := range grid {
@@ -16,6 +23,10 @@ func maxAreaOfIsland(grid [][]int) int {
1623
return res
1724
}
1825

26+
func isInGrid(grid [][]int, x, y int) bool {
27+
return x >= 0 && x < len(grid) && y >= 0 && y < len(grid[0])
28+
}
29+
1930
func areaOfIsland(grid [][]int, x, y int) int {
2031
if !isInGrid(grid, x, y) || grid[x][y] == 0 {
2132
return 0

Algorithms/0863. All Nodes Distance K in Binary Tree/863. All Nodes Distance K in Binary Tree.go renamed to Algorithms/0863.All-Nodes-Distance-K-in-Binary-Tree/863. All Nodes Distance K in Binary Tree.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package leetcode
22

3+
import (
4+
"github.com/halfrost/LeetCode-Go/structures"
5+
)
6+
7+
// TreeNode define
8+
type TreeNode = structures.TreeNode
9+
310
/**
411
* Definition for a binary tree node.
512
* type TreeNode struct {
+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package leetcode
33
import (
44
"fmt"
55
"testing"
6+
7+
"github.com/halfrost/LeetCode-Go/structures"
68
)
79

810
type question863 struct {
@@ -29,7 +31,7 @@ func Test_Problem863(t *testing.T) {
2931
qs := []question863{
3032

3133
question863{
32-
para863{[]int{3, 5, 1, 6, 2, 0, 8, NULL, NULL, 7, 4}, []int{5}, 2},
34+
para863{[]int{3, 5, 1, 6, 2, 0, 8, structures.NULL, structures.NULL, 7, 4}, []int{5}, 2},
3335
ans863{[]int{7, 4, 1}},
3436
},
3537
}
@@ -38,7 +40,7 @@ func Test_Problem863(t *testing.T) {
3840

3941
for _, q := range qs {
4042
_, p := q.ans863, q.para863
41-
tree, target := Ints2TreeNode(p.root), Ints2TreeNode(p.target)
43+
tree, target := structures.Ints2TreeNode(p.root), structures.Ints2TreeNode(p.target)
4244
fmt.Printf("【input】:%v 【output】:%v\n", p, distanceK(tree, target, p.K))
4345
}
4446
fmt.Printf("\n\n\n")

Algorithms/0872. Leaf-Similar Trees/872. Leaf-Similar Trees.go renamed to Algorithms/0872.Leaf-Similar-Trees/872. Leaf-Similar Trees.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package leetcode
22

3+
import (
4+
"github.com/halfrost/LeetCode-Go/structures"
5+
)
6+
7+
// TreeNode define
8+
type TreeNode = structures.TreeNode
9+
310
/**
411
* Definition for a binary tree node.
512
* type TreeNode struct {

Algorithms/0872. Leaf-Similar Trees/872. Leaf-Similar Trees_test.go renamed to Algorithms/0872.Leaf-Similar-Trees/872. Leaf-Similar Trees_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package leetcode
33
import (
44
"fmt"
55
"testing"
6+
7+
"github.com/halfrost/LeetCode-Go/structures"
68
)
79

810
type question872 struct {
@@ -37,8 +39,8 @@ func Test_Problem872(t *testing.T) {
3739

3840
for _, q := range qs {
3941
_, p := q.ans872, q.para872
40-
tree1 := Ints2TreeNode(p.one)
41-
tree2 := Ints2TreeNode(p.two)
42+
tree1 := structures.Ints2TreeNode(p.one)
43+
tree2 := structures.Ints2TreeNode(p.two)
4244
fmt.Printf("【input】:%v 【output】:%v\n", p, leafSimilar(tree1, tree2))
4345
}
4446
fmt.Printf("\n\n\n")

Algorithms/1020. Number of Enclaves/1020. Number of Enclaves.go renamed to Algorithms/1020.Number-of-Enclaves/1020. Number of Enclaves.go

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package leetcode
22

3+
var dir = [][]int{
4+
[]int{-1, 0},
5+
[]int{0, 1},
6+
[]int{1, 0},
7+
[]int{0, -1},
8+
}
9+
310
func numEnclaves(A [][]int) int {
411
m, n := len(A), len(A[0])
512
for i := 0; i < m; i++ {
@@ -33,3 +40,7 @@ func dfsNumEnclaves(A [][]int, x, y int) {
3340
dfsNumEnclaves(A, nx, ny)
3441
}
3542
}
43+
44+
func isInGrid(grid [][]int, x, y int) bool {
45+
return x >= 0 && x < len(grid) && y >= 0 && y < len(grid[0])
46+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package leetcode
22

3+
import (
4+
"github.com/halfrost/LeetCode-Go/structures"
5+
)
6+
7+
// TreeNode define
8+
type TreeNode = structures.TreeNode
9+
310
/**
411
* Definition for a binary tree node.
512
* type TreeNode struct {
@@ -31,3 +38,24 @@ func dfsAncestorDiff(root *TreeNode, res *int) (int, int) {
3138
*res = max(*res, max(abs(root.Val-min(leftMin, rightMin)), abs(root.Val-max(leftMax, rightMax))))
3239
return max(leftMax, max(rightMax, root.Val)), min(leftMin, min(rightMin, root.Val))
3340
}
41+
42+
func max(a int, b int) int {
43+
if a > b {
44+
return a
45+
}
46+
return b
47+
}
48+
49+
func min(a int, b int) int {
50+
if a > b {
51+
return b
52+
}
53+
return a
54+
}
55+
56+
func abs(a int) int {
57+
if a > 0 {
58+
return a
59+
}
60+
return -a
61+
}
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package leetcode
33
import (
44
"fmt"
55
"testing"
6+
7+
"github.com/halfrost/LeetCode-Go/structures"
68
)
79

810
type question1026 struct {
@@ -32,7 +34,7 @@ func Test_Problem1026(t *testing.T) {
3234
},
3335

3436
question1026{
35-
para1026{[]int{8, 3, 10, 1, 6, NULL, 14, NULL, NULL, 4, 7, 13}},
37+
para1026{[]int{8, 3, 10, 1, 6, structures.NULL, 14, structures.NULL, structures.NULL, 4, 7, 13}},
3638
ans1026{7},
3739
},
3840

@@ -51,7 +53,7 @@ func Test_Problem1026(t *testing.T) {
5153

5254
for _, q := range qs {
5355
_, p := q.ans1026, q.para1026
54-
tree := Ints2TreeNode(p.one)
56+
tree := structures.Ints2TreeNode(p.one)
5557
fmt.Printf("【input】:%v 【output】:%v\n", p, maxAncestorDiff(tree))
5658
}
5759
fmt.Printf("\n\n\n")

Algorithms/1110. Delete Nodes And Return Forest/1110. Delete Nodes And Return Forest.go renamed to Algorithms/1110.Delete-Nodes-And-Return-Forest/1110. Delete Nodes And Return Forest.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package leetcode
22

3+
import (
4+
"github.com/halfrost/LeetCode-Go/structures"
5+
)
6+
7+
// TreeNode define
8+
type TreeNode = structures.TreeNode
9+
310
/**
411
* Definition for a binary tree node.
512
* type TreeNode struct {

Algorithms/1110. Delete Nodes And Return Forest/1110. Delete Nodes And Return Forest_test.go renamed to Algorithms/1110.Delete-Nodes-And-Return-Forest/1110. Delete Nodes And Return Forest_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package leetcode
33
import (
44
"fmt"
55
"testing"
6+
7+
"github.com/halfrost/LeetCode-Go/structures"
68
)
79

810
type question1110 struct {
@@ -29,15 +31,15 @@ func Test_Problem1110(t *testing.T) {
2931

3032
question1110{
3133
para1110{[]int{1, 2, 3, 4, 5, 6, 7}, []int{3, 5}},
32-
ans1110{[][]int{[]int{1, 2, NULL, 4}, []int{6}, []int{7}}},
34+
ans1110{[][]int{[]int{1, 2, structures.NULL, 4}, []int{6}, []int{7}}},
3335
},
3436
}
3537

3638
fmt.Printf("------------------------Leetcode Problem 1110------------------------\n")
3739

3840
for _, q := range qs {
3941
_, p := q.ans1110, q.para1110
40-
tree := Ints2TreeNode(p.one)
42+
tree := structures.Ints2TreeNode(p.one)
4143
fmt.Printf("【input】:%v 【output】:%v\n", p, delNodes(tree, p.two))
4244
}
4345
fmt.Printf("\n\n\n")

Algorithms/1145. Binary Tree Coloring Game/1145. Binary Tree Coloring Game.go renamed to Algorithms/1145.Binary-Tree-Coloring-Game/1145. Binary Tree Coloring Game.go

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package leetcode
22

3+
import (
4+
"github.com/halfrost/LeetCode-Go/structures"
5+
)
6+
7+
// TreeNode define
8+
type TreeNode = structures.TreeNode
9+
310
/**
411
* Definition for a binary tree node.
512
* type TreeNode struct {
@@ -8,6 +15,7 @@ package leetcode
815
* Right *TreeNode
916
* }
1017
*/
18+
1119
func btreeGameWinningMove(root *TreeNode, n int, x int) bool {
1220
var left, right int
1321
dfsBtreeGameWinningMove(root, &left, &right, x)

Algorithms/1145. Binary Tree Coloring Game/1145. Binary Tree Coloring Game_test.go renamed to Algorithms/1145.Binary-Tree-Coloring-Game/1145. Binary Tree Coloring Game_test.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package leetcode
33
import (
44
"fmt"
55
"testing"
6+
7+
"github.com/halfrost/LeetCode-Go/structures"
68
)
79

810
type question1145 struct {
@@ -13,33 +15,33 @@ type question1145 struct {
1315
// para 是参数
1416
// one 代表第一个参数
1517
type para1145 struct {
16-
root []int
17-
target []int
18-
K int
18+
root []int
19+
n int
20+
x int
1921
}
2022

2123
// ans 是答案
2224
// one 代表第一个答案
2325
type ans1145 struct {
24-
one []int
26+
one bool
2527
}
2628

2729
func Test_Problem1145(t *testing.T) {
2830

2931
qs := []question1145{
3032

3133
question1145{
32-
para1145{[]int{3, 5, 1, 6, 2, 0, 8, NULL, NULL, 7, 4}, []int{5}, 2},
33-
ans1145{[]int{7, 4, 1}},
34+
para1145{[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11, 3},
35+
ans1145{true},
3436
},
3537
}
3638

3739
fmt.Printf("------------------------Leetcode Problem 1145------------------------\n")
3840

3941
for _, q := range qs {
4042
_, p := q.ans1145, q.para1145
41-
tree, target := Ints2TreeNode(p.root), Ints2TreeNode(p.target)
42-
fmt.Printf("【input】:%v 【output】:%v\n", p, distanceK(tree, target, p.K))
43+
tree := structures.Ints2TreeNode(p.root)
44+
fmt.Printf("【input】:%v 【output】:%v\n", p, btreeGameWinningMove(tree, p.n, p.x))
4345
}
4446
fmt.Printf("\n\n\n")
4547
}
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ func balancedString(s string) int {
2222
}
2323
return res
2424
}
25+
26+
func min(a int, b int) int {
27+
if a > b {
28+
return b
29+
}
30+
return a
31+
}

0 commit comments

Comments
 (0)