Skip to content

Commit

Permalink
change path
Browse files Browse the repository at this point in the history
  • Loading branch information
halfrost committed Aug 7, 2020
1 parent ef3da5d commit dfde398
Show file tree
Hide file tree
Showing 253 changed files with 3,103 additions and 460 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ go:
branches:
only:
- master
- stable

script:
- go get -t -v ./...
Expand Down
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": []
}
]
}
8 changes: 8 additions & 0 deletions Algorithms/0002. Add Two Numbers/2. Add Two Numbers.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package leetcode

import (
"github.com/halfrost/LeetCode-Go/structures"
)

// ListNode define
type ListNode = structures.ListNode

/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/

func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
if l1 == nil || l2 == nil {
return nil
Expand Down
4 changes: 3 additions & 1 deletion Algorithms/0002. Add Two Numbers/2. Add Two Numbers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package leetcode
import (
"fmt"
"testing"

"github.com/halfrost/LeetCode-Go/structures"
)

type question2 struct {
Expand Down Expand Up @@ -73,7 +75,7 @@ func Test_Problem2(t *testing.T) {

for _, q := range qs {
_, p := q.ans2, q.para2
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(addTwoNumbers(S2l(p.one), S2l(p.another))))
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(addTwoNumbers(structures.Ints2List(p.one), structures.Ints2List(p.another))))
}
fmt.Printf("\n\n\n")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ func lengthOfLongestSubstring(s string) int {
}
return result
}

func max(a int, b int) int {
if a > b {
return a
}
return b
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {
}
return float64(midLeft+midRight) / 2
}

func max(a int, b int) int {
if a > b {
return a
}
return b
}

func min(a int, b int) int {
if a > b {
return b
}
return a
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package leetcode

import (
"github.com/halfrost/LeetCode-Go/structures"
)

// ListNode define
type ListNode = structures.ListNode

/**
* Definition for singly-linked list.
* type ListNode struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package leetcode
import (
"fmt"
"testing"

"github.com/halfrost/LeetCode-Go/structures"
)

type question19 struct {
Expand Down Expand Up @@ -50,23 +52,13 @@ func Test_Problem19(t *testing.T) {
para19{[]int{1, 2, 3, 4, 5}, 5},
ans19{[]int{2, 3, 4, 5}},
},

question19{
para19{[]int{1, 2, 3, 4, 5}, 0},
ans19{[]int{1, 2, 3, 4, 5}},
},

question19{
para19{[]int{1, 2, 3, 4, 5}, 10},
ans19{[]int{1, 2, 3, 4, 5}},
},
}

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

for _, q := range qs {
_, p := q.ans19, q.para19
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(removeNthFromEnd(S2l(p.one), p.n)))
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(removeNthFromEnd(structures.Ints2List(p.one), p.n)))
}
fmt.Printf("\n\n\n")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package leetcode

import (
"github.com/halfrost/LeetCode-Go/structures"
)

// ListNode define
type ListNode = structures.ListNode

/**
* Definition for singly-linked list.
* type ListNode struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package leetcode
import (
"fmt"
"testing"

"github.com/halfrost/LeetCode-Go/structures"
)

type question21 struct {
Expand Down Expand Up @@ -73,7 +75,7 @@ func Test_Problem21(t *testing.T) {

for _, q := range qs {
_, p := q.ans21, q.para21
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(mergeTwoLists(S2l(p.one), S2l(p.another))))
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(mergeTwoLists(structures.Ints2List(p.one), structures.Ints2List(p.another))))
}
fmt.Printf("\n\n\n")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package leetcode

import (
"github.com/halfrost/LeetCode-Go/structures"
)

// ListNode define
type ListNode = structures.ListNode

/**
* Definition for singly-linked list.
* type ListNode struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package leetcode
import (
"fmt"
"testing"

"github.com/halfrost/LeetCode-Go/structures"
)

type question23 struct {
Expand Down Expand Up @@ -94,9 +96,9 @@ func Test_Problem23(t *testing.T) {
for _, q := range qs {
var ls []*ListNode
for _, qq := range q.para23.one {
ls = append(ls, S2l(qq))
ls = append(ls, structures.Ints2List(qq))
}
fmt.Printf("【input】:%v 【output】:%v\n", q.para23.one, L2s(mergeKLists(ls)))
fmt.Printf("【input】:%v 【output】:%v\n", q.para23.one, structures.List2Ints(mergeKLists(ls)))
}
fmt.Printf("\n\n\n")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package leetcode

import (
"github.com/halfrost/LeetCode-Go/structures"
)

// ListNode define
type ListNode = structures.ListNode

/**
* Definition for singly-linked list.
* type ListNode struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package leetcode
import (
"fmt"
"testing"

"github.com/halfrost/LeetCode-Go/structures"
)

type question24 struct {
Expand Down Expand Up @@ -53,39 +55,7 @@ func Test_Problem24(t *testing.T) {

for _, q := range qs {
_, p := q.ans24, q.para24
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(swapPairs(S2l(p.one))))
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(swapPairs(structures.Ints2List(p.one))))
}
fmt.Printf("\n\n\n")
}

// convert *ListNode to []int
func L2s(head *ListNode) []int {
res := []int{}

for head != nil {
res = append(res, head.Val)
head = head.Next
}

return res
}

// convert []int to *ListNode
func S2l(nums []int) *ListNode {
if len(nums) == 0 {
return nil
}

res := &ListNode{
Val: nums[0],
}
temp := res
for i := 1; i < len(nums); i++ {
temp.Next = &ListNode{
Val: nums[i],
}
temp = temp.Next
}

return res
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package leetcode

import (
"github.com/halfrost/LeetCode-Go/structures"
)

// ListNode define
type ListNode = structures.ListNode

/**
* Definition for singly-linked list.
* type ListNode struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package leetcode
import (
"fmt"
"testing"

"github.com/halfrost/LeetCode-Go/structures"
)

type question25 struct {
Expand Down Expand Up @@ -48,7 +50,7 @@ func Test_Problem25(t *testing.T) {

for _, q := range qs {
_, p := q.ans25, q.para25
fmt.Printf("【input】:%v 【output】:%v\n", p, L2s(reverseKGroup(S2l(p.one), p.two)))
fmt.Printf("【input】:%v 【output】:%v\n", p, structures.List2Ints(reverseKGroup(structures.Ints2List(p.one), p.two)))
}
fmt.Printf("\n\n\n")
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,10 @@ func divide1(divided int, divisor int) int {
}
return sign * result
}

func abs(a int) int {
if a > 0 {
return a
}
return -a
}
7 changes: 7 additions & 0 deletions Algorithms/0053. Maximum Subarray/53. Maximum Subarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ func maxSubArray1(nums []int) int {
}
return maxSum
}

func max(a int, b int) int {
if a > b {
return a
}
return b
}
10 changes: 5 additions & 5 deletions Algorithms/0054. Spiral Matrix/54. Spiral Matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func spiralOrder2(matrix [][]int) []int {
}

// top、left、right、bottom 分别是剩余区域的上、左、右、下的下标
top, left, bottom, right := 0, 0, m-1, n-1
top, left, bottom, right := 0, 0, m-1, n-1
count, sum := 0, m*n
res := []int{}

// 外层循环每次遍历一圈
for count < sum {
i, j := top, left
Expand All @@ -93,19 +93,19 @@ func spiralOrder2(matrix [][]int) []int {
count++
j++
}
i, j = top + 1, right
i, j = top+1, right
for i <= bottom && count < sum {
res = append(res, matrix[i][j])
count++
i++
}
i, j = bottom, right - 1
i, j = bottom, right-1
for j >= left && count < sum {
res = append(res, matrix[i][j])
count++
j--
}
i, j = bottom - 1, left
i, j = bottom-1, left
for i > top && count < sum {
res = append(res, matrix[i][j])
count++
Expand Down
13 changes: 7 additions & 6 deletions Algorithms/0056. Merge Intervals/56. Merge Intervals.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package leetcode

import (
"github.com/halfrost/LeetCode-Go/structures"
)

// Interval define
type Interval = structures.Interval

/**
* Definition for an interval.
* type Interval struct {
Expand All @@ -8,12 +15,6 @@ package leetcode
* }
*/

// Interval define
type Interval struct {
Start int
End int
}

func merge56(intervals []Interval) []Interval {
if len(intervals) == 0 {
return intervals
Expand Down
Loading

0 comments on commit dfde398

Please sign in to comment.