Skip to content

Commit

Permalink
refactor: datastruct (#81)
Browse files Browse the repository at this point in the history
Signed-off-by: ashing <axingfly@gmail.com>
  • Loading branch information
ronething authored Feb 10, 2024
1 parent 06ab053 commit b882654
Show file tree
Hide file tree
Showing 98 changed files with 422 additions and 348 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: go mod tidy

- name: run codecov.sh
run: bash script/codecov.sh
run: bash scripts/codecov.sh

- name: Publish to codecov.io
run: bash <(curl -s https://codecov.io/bash)
run: bash <(curl -s https://codecov.io/bash)
16 changes: 15 additions & 1 deletion .github/workflows/go-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ jobs:
echo "Files are not formatted by gofmt:"
echo $diffs
exit 1
fi
fi
sort-import-lint:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Setup Go Environment
uses: actions/setup-go@v3
with:
go-version: "1.21.3"
- name: Sort Import Lint
run: make sort-import
- name: Check for changes
run: |
git diff --exit-code || { echo "Go imports revisions detected. Please run make sort-import and commit changes."; exit 1; }
2 changes: 1 addition & 1 deletion .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
ci
chore
revert
change
change
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: sort-import
sort-import:
@./scripts/goimports-reviser.sh
3 changes: 2 additions & 1 deletion jianzhioffer/03/main_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestFindRepeatNumber(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion jianzhioffer/04/04_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package _4

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestFindNumberIn2DArray(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion jianzhioffer/05/main_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestReplaceSpace(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions jianzhioffer/06/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"algorithm/guns"
"algorithm/template"
)

type ListNode = guns.ListNode
type ListNode = template.ListNode

func reversePrint(head *ListNode) []int {
res := make([]int, 0)
Expand Down
3 changes: 2 additions & 1 deletion jianzhioffer/06/main_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestReversePrint(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions jianzhioffer/07/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import "algorithm/guns"
import (
"algorithm/template"
)

type TreeNode = guns.TreeNode
type TreeNode = template.TreeNode

type tree struct {
preorder []int
Expand Down
3 changes: 2 additions & 1 deletion jianzhioffer/09/main_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCQueue_AppendTail(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion jianzhioffer/11/main_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestMinArray(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion jianzhioffer/12/main_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/bmizerany/assert"
"testing"

"github.com/bmizerany/assert"
)

func TestExist(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions lcp/44/LCP 44. 开幕式焰火.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package _4

import "algorithm/guns"
import (
"algorithm/template"
)

type TreeNode = guns.TreeNode
type TreeNode = template.TreeNode

func numColor(root *TreeNode) int {
// 遍历之后进行去重
Expand Down
2 changes: 1 addition & 1 deletion leetcode/0022/0022.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
)

//https://leetcode-cn.com/problems/generate-parentheses/solution/gua-hao-sheng-cheng-by-leetcode-solution/
// https://leetcode-cn.com/problems/generate-parentheses/solution/gua-hao-sheng-cheng-by-leetcode-solution/
func generateParenthesis(n int) []string {
ans := make([]string, 0)
backTrack([]string{}, 0, 0, &ans, n)
Expand Down
8 changes: 4 additions & 4 deletions leetcode/0053/0059.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

//输入: [-2,1,-3,4,-1,2,1,-5,4]
//输出: 6
//maxSubArray
//https://leetcode-cn.com/problems/maximum-subarray/solution/zui-da-zi-xu-he-by-leetcode-solution/
// 输入: [-2,1,-3,4,-1,2,1,-5,4]
// 输出: 6
// maxSubArray
// https://leetcode-cn.com/problems/maximum-subarray/solution/zui-da-zi-xu-he-by-leetcode-solution/
func maxSubArray(nums []int) int {
max := nums[0]
for i := 1; i < len(nums); i++ {
Expand Down
8 changes: 4 additions & 4 deletions leetcode/0101/0101_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/stretchr/testify/assert"
)

//[1,2,2,3,4,4,3]
//[1,2,2,null,3,null,3]
//[]
// [1,2,2,3,4,4,3]
// [1,2,2,null,3,null,3]
// []
func TestIsSymmetric(t *testing.T) {
t.Run("nil", func(t *testing.T) {
r := isSymmetric(nil)
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestIsSymmetric(t *testing.T) {
})
}

//TODO:构建树
// TODO:构建树
func BuildTree(nums []int) *TreeNode {
return nil
}
6 changes: 4 additions & 2 deletions leetcode/0104/104. Maximum Depth of Binary Tree.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package _104

import "algorithm/guns"
import (
"algorithm/template"
)

type TreeNode = guns.TreeNode
type TreeNode = template.TreeNode

func maxDepth(root *TreeNode) int {
return subMaxDepth(root)
Expand Down
6 changes: 4 additions & 2 deletions leetcode/0129/129. Sum Root to Leaf Numbers.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package _129

import "algorithm/guns"
import (
"algorithm/template"
)

type TreeNode = guns.TreeNode
type TreeNode = template.TreeNode

func dfs(root *TreeNode, prevSum int) int {
if root == nil {
Expand Down
6 changes: 4 additions & 2 deletions leetcode/0143/143. Reorder List.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package _143

import "algorithm/guns"
import (
"algorithm/template"
)

type ListNode = guns.ListNode
type ListNode = template.ListNode

func reorderList(head *ListNode) {
//边界判定
Expand Down
6 changes: 4 additions & 2 deletions leetcode/0144/144. Binary Tree Preorder Traversal.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package _144

import "algorithm/guns"
import (
"algorithm/template"
)

type TreeNode = guns.TreeNode
type TreeNode = template.TreeNode

func preorderTraversal(root *TreeNode) []int {
return sub(root)
Expand Down
4 changes: 2 additions & 2 deletions leetcode/0206/go/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"algorithm/guns"
"algorithm/template"
)

/**
Expand All @@ -12,7 +12,7 @@ import (
* }
*/

type ListNode = guns.ListNode
type ListNode = template.ListNode

func reverseList(head *ListNode) *ListNode {
if head == nil || head.Next == nil {
Expand Down
2 changes: 1 addition & 1 deletion leetcode/0226/0226.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

//TreeNode 二叉树节点
// TreeNode 二叉树节点
type TreeNode struct {
Val int
Left *TreeNode
Expand Down
6 changes: 4 additions & 2 deletions leetcode/0234/234. Palindrome Linked List.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package _234

import "algorithm/guns"
import (
"algorithm/template"
)

type ListNode = guns.ListNode
type ListNode = template.ListNode

func isPalindrome(head *ListNode) bool {
//使用数组存储
Expand Down
7 changes: 4 additions & 3 deletions leetcode/0234/234. Palindrome Linked List_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package _234
import (
"testing"

"algorithm/guns"
"github.com/bmizerany/assert"

"algorithm/template"
)

func Test_isPalindrome(t *testing.T) {
assert.Equal(
t,
false,
isPalindrome(guns.GenLinkList([]int{1, 2})),
isPalindrome(template.GenLinkList([]int{1, 2})),
)
assert.Equal(
t,
true,
isPalindrome(guns.GenLinkList([]int{1, 2, 2, 1})),
isPalindrome(template.GenLinkList([]int{1, 2, 2, 1})),
)
}
6 changes: 4 additions & 2 deletions leetcode/0404/0404.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import "algorithm/guns"
import (
"algorithm/template"
)

type TreeNode = guns.TreeNode // 修改签名,下面的 TreeNode 就不需要变
type TreeNode = template.TreeNode // 修改签名,下面的 TreeNode 就不需要变

func sumOfLeftLeaves(root *TreeNode) int {
//return subSumOfLeftLeaves(root, false, 0)
Expand Down
2 changes: 1 addition & 1 deletion leetcode/0925/925. Long Pressed Name.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func isLongPressedName(name string, typed string) bool {
return false
}

//双指针
// 双指针
func isLongPressedNamePlanB(name string, typed string) bool {
i, j := 0, 0
for j < len(typed) {
Expand Down
3 changes: 2 additions & 1 deletion leetcode/148. Sort List.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package leetcode

import (
"algorithm/topic/linkedlist"
"sort"

"algorithm/topic/linkedlist"
)

type ListNode = linkedlist.ListNode
Expand Down
2 changes: 1 addition & 1 deletion leetcode/1927/1927. Sum Game.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package _1927

import "log"

//参考题解: https://leetcode-cn.com/problems/sum-game/solution/shu-xue-jie-fa-by-newhar-fqjs/
// 参考题解: https://leetcode-cn.com/problems/sum-game/solution/shu-xue-jie-fa-by-newhar-fqjs/
func sumGame(num string) bool {
sum1 := 0
cnt1 := 0
Expand Down
4 changes: 2 additions & 2 deletions leetcode_91_2/2020/0023/23. Merge k Sorted Lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package _023
import (
"sort"

"algorithm/guns"
"algorithm/template"
)

type ListNode = guns.ListNode
type ListNode = template.ListNode

type Queue struct {
element []*ListNode
Expand Down
4 changes: 2 additions & 2 deletions leetcode_91_2/2020/0024/24. Swap Nodes in Pairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package _024
import (
"fmt"

"algorithm/guns"
"algorithm/template"
)

type ListNode = guns.ListNode
type ListNode = template.ListNode

// var swapPairs = swapPairs1
func swapPairs1(head *ListNode) *ListNode {
Expand Down
4 changes: 2 additions & 2 deletions leetcode_91_2/2020/0061/0061_2/61. Rotate List.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package _061
import (
"fmt"

"algorithm/guns"
"algorithm/template"
)

type ListNode = guns.ListNode
type ListNode = template.ListNode

func rotateRight(head *ListNode, k int) *ListNode {
if head == nil || head.Next == nil {
Expand Down
Loading

0 comments on commit b882654

Please sign in to comment.