Skip to content

Commit a2bdbb7

Browse files
authored
Merge pull request halfrost#33 from halfrost/test_travis-ci
change path
2 parents 1934e38 + 1081638 commit a2bdbb7

File tree

238 files changed

+2024
-460
lines changed

Some content is hidden

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

238 files changed

+2024
-460
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ go:
77
branches:
88
only:
99
- master
10-
- stable
1110

1211
script:
1312
- go get -t -v ./...

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// 使用 IntelliSense 了解相关属性。
3+
// 悬停以查看现有属性的描述。
4+
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "auto",
12+
"program": "${fileDirname}",
13+
"env": {},
14+
"args": []
15+
}
16+
]
17+
}

Algorithms/0002. Add Two Numbers/2. Add Two Numbers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
package leetcode
22

3+
import (
4+
"github.com/halfrost/LeetCode-Go/structures"
5+
)
6+
7+
// ListNode define
8+
type ListNode = structures.ListNode
9+
310
/**
411
* Definition for singly-linked list.
512
* type ListNode struct {
613
* Val int
714
* Next *ListNode
815
* }
916
*/
17+
1018
func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
1119
if l1 == nil || l2 == nil {
1220
return nil

Algorithms/0002. Add Two Numbers/2. Add Two Numbers_test.go

Lines changed: 3 additions & 1 deletion
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 question2 struct {
@@ -73,7 +75,7 @@ func Test_Problem2(t *testing.T) {
7375

7476
for _, q := range qs {
7577
_, p := q.ans2, q.para2
76-
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(addTwoNumbers(S2l(p.one), S2l(p.another))))
78+
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(addTwoNumbers(structures.Ints2List(p.one), structures.Ints2List(p.another))))
7779
}
7880
fmt.Printf("\n\n\n")
7981
}

Algorithms/0003. Longest Substring Without Repeating Characters/3. Longest Substring Without Repeating Characters.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ func lengthOfLongestSubstring(s string) int {
2020
}
2121
return result
2222
}
23+
24+
func max(a int, b int) int {
25+
if a > b {
26+
return a
27+
}
28+
return b
29+
}

Algorithms/0004. Median of Two Sorted Arrays/4. Median of Two Sorted Arrays.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,17 @@ func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {
4141
}
4242
return float64(midLeft+midRight) / 2
4343
}
44+
45+
func max(a int, b int) int {
46+
if a > b {
47+
return a
48+
}
49+
return b
50+
}
51+
52+
func min(a int, b int) int {
53+
if a > b {
54+
return b
55+
}
56+
return a
57+
}

Algorithms/0019. Remove Nth Node From End of List/19. Remove Nth Node From End of List.go

Lines changed: 7 additions & 0 deletions
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+
// ListNode define
8+
type ListNode = structures.ListNode
9+
310
/**
411
* Definition for singly-linked list.
512
* type ListNode struct {

Algorithms/0019. Remove Nth Node From End of List/19. Remove Nth Node From End of List_test.go

Lines changed: 3 additions & 11 deletions
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 question19 struct {
@@ -50,23 +52,13 @@ func Test_Problem19(t *testing.T) {
5052
para19{[]int{1, 2, 3, 4, 5}, 5},
5153
ans19{[]int{2, 3, 4, 5}},
5254
},
53-
54-
question19{
55-
para19{[]int{1, 2, 3, 4, 5}, 0},
56-
ans19{[]int{1, 2, 3, 4, 5}},
57-
},
58-
59-
question19{
60-
para19{[]int{1, 2, 3, 4, 5}, 10},
61-
ans19{[]int{1, 2, 3, 4, 5}},
62-
},
6355
}
6456

6557
fmt.Printf("------------------------Leetcode Problem 19------------------------\n")
6658

6759
for _, q := range qs {
6860
_, p := q.ans19, q.para19
69-
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(removeNthFromEnd(S2l(p.one), p.n)))
61+
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(removeNthFromEnd(structures.Ints2List(p.one), p.n)))
7062
}
7163
fmt.Printf("\n\n\n")
7264
}

Algorithms/0021. Merge Two Sorted Lists/21. Merge Two Sorted Lists.go

Lines changed: 7 additions & 0 deletions
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+
// ListNode define
8+
type ListNode = structures.ListNode
9+
310
/**
411
* Definition for singly-linked list.
512
* type ListNode struct {

Algorithms/0021. Merge Two Sorted Lists/21. Merge Two Sorted Lists_test.go

Lines changed: 3 additions & 1 deletion
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 question21 struct {
@@ -73,7 +75,7 @@ func Test_Problem21(t *testing.T) {
7375

7476
for _, q := range qs {
7577
_, p := q.ans21, q.para21
76-
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(mergeTwoLists(S2l(p.one), S2l(p.another))))
78+
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(mergeTwoLists(structures.Ints2List(p.one), structures.Ints2List(p.another))))
7779
}
7880
fmt.Printf("\n\n\n")
7981
}

Algorithms/0023. Merge k Sorted Lists/23. Merge k Sorted Lists.go

Lines changed: 7 additions & 0 deletions
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+
// ListNode define
8+
type ListNode = structures.ListNode
9+
310
/**
411
* Definition for singly-linked list.
512
* type ListNode struct {

Algorithms/0023. Merge k Sorted Lists/23. Merge k Sorted Lists_test.go

Lines changed: 4 additions & 2 deletions
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 question23 struct {
@@ -94,9 +96,9 @@ func Test_Problem23(t *testing.T) {
9496
for _, q := range qs {
9597
var ls []*ListNode
9698
for _, qq := range q.para23.one {
97-
ls = append(ls, S2l(qq))
99+
ls = append(ls, structures.Ints2List(qq))
98100
}
99-
fmt.Printf("【input】:%v 【output】:%v\n", q.para23.one, L2s(mergeKLists(ls)))
101+
fmt.Printf("【input】:%v 【output】:%v\n", q.para23.one, structures.List2Ints(mergeKLists(ls)))
100102
}
101103
fmt.Printf("\n\n\n")
102104
}

Algorithms/0024. Swap Nodes in Pairs/24. Swap Nodes in Pairs.go

Lines changed: 7 additions & 0 deletions
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+
// ListNode define
8+
type ListNode = structures.ListNode
9+
310
/**
411
* Definition for singly-linked list.
512
* type ListNode struct {

Algorithms/0024. Swap Nodes in Pairs/24. Swap Nodes in Pairs_test.go

Lines changed: 3 additions & 33 deletions
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 question24 struct {
@@ -53,39 +55,7 @@ func Test_Problem24(t *testing.T) {
5355

5456
for _, q := range qs {
5557
_, p := q.ans24, q.para24
56-
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(swapPairs(S2l(p.one))))
58+
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(swapPairs(structures.Ints2List(p.one))))
5759
}
5860
fmt.Printf("\n\n\n")
5961
}
60-
61-
// convert *ListNode to []int
62-
func L2s(head *ListNode) []int {
63-
res := []int{}
64-
65-
for head != nil {
66-
res = append(res, head.Val)
67-
head = head.Next
68-
}
69-
70-
return res
71-
}
72-
73-
// convert []int to *ListNode
74-
func S2l(nums []int) *ListNode {
75-
if len(nums) == 0 {
76-
return nil
77-
}
78-
79-
res := &ListNode{
80-
Val: nums[0],
81-
}
82-
temp := res
83-
for i := 1; i < len(nums); i++ {
84-
temp.Next = &ListNode{
85-
Val: nums[i],
86-
}
87-
temp = temp.Next
88-
}
89-
90-
return res
91-
}

Algorithms/0025. Reverse Nodes in k Group/25. Reverse Nodes in k Group.go

Lines changed: 7 additions & 0 deletions
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+
// ListNode define
8+
type ListNode = structures.ListNode
9+
310
/**
411
* Definition for singly-linked list.
512
* type ListNode struct {

Algorithms/0025. Reverse Nodes in k Group/25. Reverse Nodes in k Group_test.go

Lines changed: 3 additions & 1 deletion
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 question25 struct {
@@ -48,7 +50,7 @@ func Test_Problem25(t *testing.T) {
4850

4951
for _, q := range qs {
5052
_, p := q.ans25, q.para25
51-
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(reverseKGroup(S2l(p.one), p.two)))
53+
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(reverseKGroup(structures.Ints2List(p.one), p.two)))
5254
}
5355
fmt.Printf("\n\n\n")
5456
}

Algorithms/0029. Divide Two Integers/29. Divide Two Integers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ func divide1(divided int, divisor int) int {
9191
}
9292
return sign * result
9393
}
94+
95+
func abs(a int) int {
96+
if a > 0 {
97+
return a
98+
}
99+
return -a
100+
}

Algorithms/0053. Maximum Subarray/53. Maximum Subarray.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ func maxSubArray1(nums []int) int {
3939
}
4040
return maxSum
4141
}
42+
43+
func max(a int, b int) int {
44+
if a > b {
45+
return a
46+
}
47+
return b
48+
}

Algorithms/0054. Spiral Matrix/54. Spiral Matrix.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func spiralOrder2(matrix [][]int) []int {
8181
}
8282

8383
// top、left、right、bottom 分别是剩余区域的上、左、右、下的下标
84-
top, left, bottom, right := 0, 0, m-1, n-1
84+
top, left, bottom, right := 0, 0, m-1, n-1
8585
count, sum := 0, m*n
8686
res := []int{}
87-
87+
8888
// 外层循环每次遍历一圈
8989
for count < sum {
9090
i, j := top, left
@@ -93,19 +93,19 @@ func spiralOrder2(matrix [][]int) []int {
9393
count++
9494
j++
9595
}
96-
i, j = top + 1, right
96+
i, j = top+1, right
9797
for i <= bottom && count < sum {
9898
res = append(res, matrix[i][j])
9999
count++
100100
i++
101101
}
102-
i, j = bottom, right - 1
102+
i, j = bottom, right-1
103103
for j >= left && count < sum {
104104
res = append(res, matrix[i][j])
105105
count++
106106
j--
107107
}
108-
i, j = bottom - 1, left
108+
i, j = bottom-1, left
109109
for i > top && count < sum {
110110
res = append(res, matrix[i][j])
111111
count++

Algorithms/0056. Merge Intervals/56. Merge Intervals.go

Lines changed: 7 additions & 6 deletions
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+
// Interval define
8+
type Interval = structures.Interval
9+
310
/**
411
* Definition for an interval.
512
* type Interval struct {
@@ -8,12 +15,6 @@ package leetcode
815
* }
916
*/
1017

11-
// Interval define
12-
type Interval struct {
13-
Start int
14-
End int
15-
}
16-
1718
func merge56(intervals []Interval) []Interval {
1819
if len(intervals) == 0 {
1920
return intervals

0 commit comments

Comments
 (0)