Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions problems/add-one-row-to-tree/add_one_row_to_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package problem623

import "github.com/openset/leetcode/internal/kit"

// TreeNode - Definition for a binary tree node.
type TreeNode = kit.TreeNode

/**
Expand Down
1 change: 1 addition & 0 deletions problems/add-two-numbers-ii/add_two_numbers_ii.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package problem445

import "github.com/openset/leetcode/internal/kit"

// ListNode - Definition for singly-linked list.
type ListNode = kit.ListNode

/**
Expand Down
1 change: 1 addition & 0 deletions problems/add-two-numbers/add_two_numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package problem2

import "github.com/openset/leetcode/internal/kit"

// ListNode - Definition for singly-linked list.
type ListNode = kit.ListNode

/**
Expand Down
1 change: 1 addition & 0 deletions problems/balanced-binary-tree/balanced_binary_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package problem110

import "github.com/openset/leetcode/internal/kit"

// TreeNode - Definition for a binary tree node.
type TreeNode = kit.TreeNode

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package problem606
import (
"strconv"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

// TreeNode - Definition for a binary tree node.
type TreeNode = kit.TreeNode

/**
* Definition for a binary tree node.
* type TreeNode struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package problem606
import (
"testing"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

type caseType struct {
Expand All @@ -18,12 +18,12 @@ func TestTree2str(t *testing.T) {
expected: "1(2(4))(3)",
},
{
input: []int{1, 2, 3, NULL, 4},
input: []int{1, 2, 3, kit.NULL, 4},
expected: "1(2()(4))(3)",
},
}
for _, tc := range tests {
output := tree2str(SliceInt2TreeNode(tc.input))
output := tree2str(kit.SliceInt2TreeNode(tc.input))
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package problem108

import "github.com/openset/leetcode/internal/kit"

// TreeNode - Definition for a binary tree node.
type TreeNode = kit.TreeNode

/**
Expand Down
5 changes: 4 additions & 1 deletion problems/cousins-in-binary-tree/cousins_in_binary_tree.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package problem993

import . "github.com/openset/leetcode/internal/kit"
import "github.com/openset/leetcode/internal/kit"

// TreeNode - Definition for a binary tree node.
type TreeNode = kit.TreeNode

/**
* Definition for a binary tree node.
Expand Down
12 changes: 6 additions & 6 deletions problems/cousins-in-binary-tree/cousins_in_binary_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package problem993
import (
"testing"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

type caseType struct {
Expand All @@ -22,32 +22,32 @@ func TestIsCousins(t *testing.T) {
expected: false,
},
{
input: []int{1, 2, 3, NULL, 4, NULL, 5},
input: []int{1, 2, 3, kit.NULL, 4, kit.NULL, 5},
x: 5,
y: 4,
expected: true,
},
{
input: []int{1, 2, 3, NULL, 4},
input: []int{1, 2, 3, kit.NULL, 4},
x: 2,
y: 3,
expected: false,
},
{
input: []int{1, 2, 3, NULL, 4, 5},
input: []int{1, 2, 3, kit.NULL, 4, 5},
x: 4,
y: 5,
expected: true,
},
{
input: []int{1, 2, 3, NULL, 4, 5},
input: []int{1, 2, 3, kit.NULL, 4, 5},
x: 5,
y: 4,
expected: true,
},
}
for _, tc := range tests {
output := isCousins(SliceInt2TreeNode(tc.input), tc.x, tc.y)
output := isCousins(kit.SliceInt2TreeNode(tc.input), tc.x, tc.y)
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package problem237

import . "github.com/openset/leetcode/internal/kit"
import "github.com/openset/leetcode/internal/kit"

// ListNode - Definition for singly-linked list.
type ListNode = kit.ListNode

/**
* Definition for singly-linked list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

type caseType struct {
Expand Down Expand Up @@ -42,13 +42,13 @@ func TestDeleteNode(t *testing.T) {
},
}
for _, tc := range tests {
head := SliceInt2ListNode(tc.input)
head := kit.SliceInt2ListNode(tc.input)
node := head
for node != nil && node.Val != tc.node {
node = node.Next
}
deleteNode(node)
output := ListNode2SliceInt(head)
output := kit.ListNode2SliceInt(head)
if !reflect.DeepEqual(output, tc.expected) {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package problem350
import (
"testing"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

type caseType struct {
Expand Down Expand Up @@ -32,7 +32,7 @@ func TestIntersect(t *testing.T) {
}
for _, tc := range tests {
output := intersect(tc.nums1, tc.nums2)
if !IsEqualSliceInt(output, tc.expected) {
if !kit.IsEqualSliceInt(output, tc.expected) {
t.Fatalf("input: %v %v, output: %v, expected: %v", tc.nums1, tc.nums2, output, tc.expected)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package problem160

import . "github.com/openset/leetcode/internal/kit"
import "github.com/openset/leetcode/internal/kit"

// ListNode - Definition for singly-linked list.
type ListNode = kit.ListNode

/**
* Definition for singly-linked list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package problem160
import (
"testing"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

type caseType struct {
Expand Down Expand Up @@ -36,9 +36,9 @@ func TestGetIntersectionNode(t *testing.T) {
},
}
for _, tc := range tests {
intersection := SliceInt2ListNode(tc.intersection)
headA := SliceInt2ListNode(tc.headA)
headB := SliceInt2ListNode(tc.headB)
intersection := kit.SliceInt2ListNode(tc.intersection)
headA := kit.SliceInt2ListNode(tc.headA)
headB := kit.SliceInt2ListNode(tc.headB)
for n := headA; n != nil; n = n.Next {
if n.Next == nil {
n.Next = intersection
Expand Down
5 changes: 4 additions & 1 deletion problems/linked-list-cycle/linked_list_cycle.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package problem141

import . "github.com/openset/leetcode/internal/kit"
import "github.com/openset/leetcode/internal/kit"

// ListNode - Definition for singly-linked list.
type ListNode = kit.ListNode

/**
* Definition for singly-linked list.
Expand Down
4 changes: 2 additions & 2 deletions problems/linked-list-cycle/linked_list_cycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package problem141
import (
"testing"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

type caseType struct {
Expand Down Expand Up @@ -36,7 +36,7 @@ func TestHasCycle(t *testing.T) {
},
}
for _, tc := range tests {
input := SliceInt2ListNode(tc.input)
input := kit.SliceInt2ListNode(tc.input)
p, curr := input, input
for i := 0; curr != nil && tc.pos >= 0; i, curr = i+1, curr.Next {
if i == tc.pos {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package problem104

import . "github.com/openset/leetcode/internal/kit"
import "github.com/openset/leetcode/internal/kit"

// TreeNode - Definition for a binary tree node.
type TreeNode = kit.TreeNode

/**
* Definition for a binary tree node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package problem104
import (
"testing"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

type caseType struct {
Expand All @@ -14,24 +14,24 @@ type caseType struct {
func TestMaxDepth(t *testing.T) {
tests := [...]caseType{
{
input: []int{3, 9, 20, NULL, NULL, 15, 7},
input: []int{3, 9, 20, kit.NULL, kit.NULL, 15, 7},
expected: 3,
},
{
input: []int{1, 2, 3, NULL, 5, 6},
input: []int{1, 2, 3, kit.NULL, 5, 6},
expected: 3,
},
{
input: []int{1, 2, NULL, NULL, 5},
input: []int{1, 2, kit.NULL, kit.NULL, 5},
expected: 3,
},
{
input: []int{1, NULL, 3, NULL, 5},
input: []int{1, kit.NULL, 3, kit.NULL, 5},
expected: 3,
},
}
for _, tc := range tests {
output := maxDepth(SliceInt2TreeNode(tc.input))
output := maxDepth(kit.SliceInt2TreeNode(tc.input))
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {
if count&1 == 1 {
k := (count - 1) / 2
return float64(s[k])
} else {
k := count / 2
return (float64(s[k-1]) + float64(s[k])) / 2
}
k := count / 2
return (float64(s[k-1]) + float64(s[k])) / 2
}
5 changes: 4 additions & 1 deletion problems/merge-two-binary-trees/merge_two_binary_trees.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package problem617

import . "github.com/openset/leetcode/internal/kit"
import "github.com/openset/leetcode/internal/kit"

// TreeNode - Definition for a binary tree node.
type TreeNode = kit.TreeNode

/**
* Definition for a binary tree node.
Expand Down
10 changes: 5 additions & 5 deletions problems/merge-two-binary-trees/merge_two_binary_trees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

type caseType struct {
Expand All @@ -17,13 +17,13 @@ func TestMergeTrees(t *testing.T) {
tests := [...]caseType{
{
t1: []int{1, 3, 2, 5},
t2: []int{2, 1, 3, NULL, 4, NULL, 7},
expected: []int{3, 4, 5, 5, 4, NULL, 7},
t2: []int{2, 1, 3, kit.NULL, 4, kit.NULL, 7},
expected: []int{3, 4, 5, 5, 4, kit.NULL, 7},
},
}
for _, tc := range tests {
t3 := mergeTrees(SliceInt2TreeNode(tc.t1), SliceInt2TreeNode(tc.t2))
output := TreeNode2SliceInt(t3)
t3 := mergeTrees(kit.SliceInt2TreeNode(tc.t1), kit.SliceInt2TreeNode(tc.t2))
output := kit.TreeNode2SliceInt(t3)
if !reflect.DeepEqual(output, tc.expected) {
t.Fatalf("input: %v %v, output: %v, expected: %v", tc.t1, tc.t2, output, tc.expected)
}
Expand Down
5 changes: 4 additions & 1 deletion problems/merge-two-sorted-lists/merge_two_sorted_lists.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package problem21

import . "github.com/openset/leetcode/internal/kit"
import "github.com/openset/leetcode/internal/kit"

// ListNode - Definition for singly-linked list.
type ListNode = kit.ListNode

/**
* Definition for singly-linked list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

. "github.com/openset/leetcode/internal/kit"
"github.com/openset/leetcode/internal/kit"
)

type caseType struct {
Expand Down Expand Up @@ -42,9 +42,9 @@ func TestMergeTwoLists(t *testing.T) {
},
}
for _, tc := range tests {
l1 := SliceInt2ListNode(tc.l1)
l2 := SliceInt2ListNode(tc.l2)
output := ListNode2SliceInt(mergeTwoLists(l1, l2))
l1 := kit.SliceInt2ListNode(tc.l1)
l2 := kit.SliceInt2ListNode(tc.l2)
output := kit.ListNode2SliceInt(mergeTwoLists(l1, l2))
if !reflect.DeepEqual(output, tc.expected) {
t.Fatalf("input: %v %v, output: %v, expected: %v", tc.l1, tc.l2, output, tc.expected)
}
Expand Down
5 changes: 4 additions & 1 deletion problems/palindrome-linked-list/palindrome_linked_list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package problem234

import . "github.com/openset/leetcode/internal/kit"
import "github.com/openset/leetcode/internal/kit"

// ListNode - Definition for singly-linked list.
type ListNode = kit.ListNode

/**
* Definition for singly-linked list.
Expand Down
Loading