Skip to content

Commit 0d6e78d

Browse files
committed
format with golint
1 parent ec56ddb commit 0d6e78d

File tree

29 files changed

+135
-137
lines changed

29 files changed

+135
-137
lines changed

algorithm/binary_search/binary_search.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package binary_search
1+
package binarysearch
22

3-
// BinarySearch 二分查找
4-
func BinarySearch(nums []int, v int) int {
3+
// Search 二分查找
4+
func Search(nums []int, v int) int {
55
length := len(nums)
66
if length == 0 {
77
return -1
@@ -23,8 +23,8 @@ func BinarySearch(nums []int, v int) int {
2323
return -1
2424
}
2525

26-
// BinarySearchRecursive 使用递归方式的二分查找
27-
func BinarySearchRecursive(nums []int, v int) int {
26+
// SearchRecursive 使用递归方式的二分查找
27+
func SearchRecursive(nums []int, v int) int {
2828
length := len(nums)
2929
if length == 0 {
3030
return -1
@@ -50,8 +50,8 @@ func bs(nums []int, v int, low, high int) int {
5050
}
5151
}
5252

53-
// BinarySearchFirst 查找第一个等于给定值的元素
54-
func BinarySearchFirst(nums []int, v int) int {
53+
// SearchFirst 查找第一个等于给定值的元素
54+
func SearchFirst(nums []int, v int) int {
5555
length := len(nums)
5656
if length == 0 {
5757
return -1
@@ -75,8 +75,8 @@ func BinarySearchFirst(nums []int, v int) int {
7575
return -1
7676
}
7777

78-
// BinarySearchLast 查找最后一个值等于给定值的元素
79-
func BinarySearchLast(nums []int, v int) int {
78+
// SearchLast 查找最后一个值等于给定值的元素
79+
func SearchLast(nums []int, v int) int {
8080
length := len(nums)
8181
if length == 0 {
8282
return -1
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package binary_search
1+
package binarysearch
22

33
import (
44
"testing"
@@ -11,55 +11,55 @@ var (
1111
)
1212

1313
func TestBinarySearch(t *testing.T) {
14-
if BinarySearch(testSlice0, 0) != -1 {
14+
if Search(testSlice0, 0) != -1 {
1515
t.Fail()
1616
}
17-
if BinarySearch(testSlice1, 0) != -1 {
17+
if Search(testSlice1, 0) != -1 {
1818
t.Fail()
1919
}
20-
if BinarySearch(testSlice1, 30) != 2 {
20+
if Search(testSlice1, 30) != 2 {
2121
t.Fail()
2222
}
2323
}
2424

2525
func TestBinarySearchRecursive(t *testing.T) {
26-
if BinarySearchRecursive(testSlice0, 0) != -1 {
26+
if SearchRecursive(testSlice0, 0) != -1 {
2727
t.Fail()
2828
}
29-
if BinarySearchRecursive(testSlice1, 0) != -1 {
29+
if SearchRecursive(testSlice1, 0) != -1 {
3030
t.Fail()
3131
}
32-
if BinarySearchRecursive(testSlice1, 30) != 2 {
32+
if SearchRecursive(testSlice1, 30) != 2 {
3333
t.Fail()
3434
}
3535
}
3636

3737
func TestBinarySearchFirst(t *testing.T) {
38-
if BinarySearchFirst(testSlice0, 0) != -1 {
38+
if SearchFirst(testSlice0, 0) != -1 {
3939
t.Fail()
4040
}
41-
if BinarySearchFirst(testSlice2, 0) != -1 {
41+
if SearchFirst(testSlice2, 0) != -1 {
4242
t.Fail()
4343
}
44-
if BinarySearchFirst(testSlice2, 30) != 1 {
44+
if SearchFirst(testSlice2, 30) != 1 {
4545
t.Fail()
4646
}
47-
if BinarySearchFirst(testSlice2, 80) != 5 {
47+
if SearchFirst(testSlice2, 80) != 5 {
4848
t.Fail()
4949
}
5050
}
5151

5252
func TestBinarySearchLast(t *testing.T) {
53-
if BinarySearchLast(testSlice0, 0) != -1 {
53+
if SearchLast(testSlice0, 0) != -1 {
5454
t.Fail()
5555
}
56-
if BinarySearchLast(testSlice2, 0) != -1 {
56+
if SearchLast(testSlice2, 0) != -1 {
5757
t.Fail()
5858
}
59-
if BinarySearchLast(testSlice2, 30) != 3 {
59+
if SearchLast(testSlice2, 30) != 3 {
6060
t.Fail()
6161
}
62-
if BinarySearchLast(testSlice2, 80) != 7 {
62+
if SearchLast(testSlice2, 80) != 7 {
6363
t.Fail()
6464
}
6565
}

algorithm/sort/bubble.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package sort
22

3-
//冒泡排序,a是数组,n表示数组大小
3+
// BubbleSort 冒泡排序,a是数组,n表示数组大小
44
func BubbleSort(a []int) {
55
n := len(a)
66
if n <= 1 {

algorithm/sort/bucket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func BucketSort(a []int) {
3939

4040
}
4141

42-
// 桶排序简单实现
42+
// BucketSortSimple 桶排序简单实现
4343
func BucketSortSimple(source []int) {
4444
if len(source) <= 1 {
4545
return

algorithm/sort/insertion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package sort
22

3-
// 插入排序,a表示数组,n表示数组大小
3+
// InsertionSort 插入排序,a表示数组,n表示数组大小
44
func InsertionSort(a []int, n int) {
55
if n <= 1 {
66
return

algorithm/sort/selection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package sort
22

3-
// 选择排序,a表示数组
3+
// SelectionSort 选择排序,a表示数组
44
func SelectionSort(a []int) {
55
length := len(a)
66
if length <= 1 {

leetcode/0036.valid-sudoku/valid_sudoku.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@ func IsValidSudoku(board [][]byte) bool {
2020
t := i/3*3 + j/3
2121
if _, exist := boxes[t][board[i][j]]; exist {
2222
return false
23-
} else {
24-
boxes[t][board[i][j]] = struct{}{}
2523
}
24+
boxes[t][board[i][j]] = struct{}{}
2625

2726
if _, exist := rows[i][board[i][j]]; exist {
2827
return false
29-
} else {
30-
rows[i][board[i][j]] = struct{}{}
3128
}
29+
rows[i][board[i][j]] = struct{}{}
3230

3331
if _, exist := columns[j][board[i][j]]; exist {
3432
return false
35-
} else {
36-
columns[j][board[i][j]] = struct{}{}
3733
}
34+
columns[j][board[i][j]] = struct{}{}
35+
3836
}
3937
}
4038

leetcode/0066.plus-one/plus_one.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package leetcode
22

33
func PlusOne(digits []int) []int {
44
flag := true
5-
for i := len(digits) - 1; i >= 0; i -= 1 {
5+
for i := len(digits) - 1; i >= 0; i-- {
66
if flag {
77
if digits[i] == 9 {
88
digits[i] = 0
99
} else {
10-
digits[i] += 1
10+
digits[i]++
1111
flag = false
1212
}
1313
}

leetcode/0104.maximum-depth-of-binary-tree/maximum_depth_of_binary_tree.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ func MaxDepth(root *TreeNode) int {
1111

1212
if left > right {
1313
return left + 1
14-
} else {
15-
return right + 1
1614
}
15+
return right + 1
16+
1717
}
1818

1919
func MaxDepthByBFS(root *TreeNode) int {

leetcode/0141.linked-list-cycle/linked_list_cycle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package leetcode
22

3-
// Definition for singly-linked list.
3+
// ListNode definition for singly-linked list.
44
type ListNode struct {
55
Val int
66
Next *ListNode

leetcode/0142.linked-list-cycle-ii/linked_list_cycle_ii.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package leetcode
22

3-
// Definition for singly-linked list.
3+
// ListNode definition for singly-linked list.
44
type ListNode struct {
55
Val int
66
Next *ListNode

leetcode/0155.min-stack/min_stack.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,50 @@ type MinStack struct {
55
length int
66
}
77

8-
/** initialize your data structure here. */
8+
// Constructor initialize your data structure here.
99
func Constructor() MinStack {
1010
return MinStack{stack: make([]int, 0), sort: make([]int, 0), length: 0}
1111
}
1212

13-
func (this *MinStack) Push(x int) {
14-
this.length = this.length + 1
15-
this.stack = append(this.stack, x)
16-
this.sort = append(this.sort, x)
17-
for i := this.length - 2; i >= 0; i-- {
18-
if this.sort[i+1] > this.sort[i] {
19-
this.sort[i+1] = this.sort[i]
20-
this.sort[i] = x
13+
func (stack *MinStack) Push(x int) {
14+
stack.length = stack.length + 1
15+
stack.stack = append(stack.stack, x)
16+
stack.sort = append(stack.sort, x)
17+
for i := stack.length - 2; i >= 0; i-- {
18+
if stack.sort[i+1] > stack.sort[i] {
19+
stack.sort[i+1] = stack.sort[i]
20+
stack.sort[i] = x
2121
} else {
2222
break
2323
}
2424
}
2525
}
2626

27-
func (this *MinStack) Pop() {
28-
if this.length == 0 {
27+
func (stack *MinStack) Pop() {
28+
if stack.length == 0 {
2929
return
3030
}
31-
val := this.stack[this.length-1]
32-
for i, v := range this.sort {
31+
val := stack.stack[stack.length-1]
32+
for i, v := range stack.sort {
3333
if v == val {
34-
this.sort = append(this.sort[:i], this.sort[i+1:]...)
34+
stack.sort = append(stack.sort[:i], stack.sort[i+1:]...)
3535
break
3636
}
3737
}
38-
this.stack = this.stack[:this.length-1]
39-
this.length = this.length - 1
38+
stack.stack = stack.stack[:stack.length-1]
39+
stack.length = stack.length - 1
4040
}
4141

42-
func (this *MinStack) Top() int {
43-
if this.length == 0 {
42+
func (stack *MinStack) Top() int {
43+
if stack.length == 0 {
4444
return 0
4545
}
46-
return this.stack[this.length-1]
46+
return stack.stack[stack.length-1]
4747
}
4848

49-
func (this *MinStack) GetMin() int {
50-
if this.length == 0 {
49+
func (stack *MinStack) GetMin() int {
50+
if stack.length == 0 {
5151
return 0
5252
}
53-
return this.sort[this.length-1]
53+
return stack.sort[stack.length-1]
5454
}

leetcode/0173.binary-search-tree-iterator/binary_search_tree_iterator.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ func Constructor(root *TreeNode) BSTIterator {
2525
}
2626
}
2727

28-
/** @return the next smallest number */
29-
func (this *BSTIterator) Next() int {
30-
n := this.stack[this.length-1]
31-
this.stack = this.stack[:this.length-1]
28+
// Next return the next smallest number
29+
func (iterator *BSTIterator) Next() int {
30+
n := iterator.stack[iterator.length-1]
31+
iterator.stack = iterator.stack[:iterator.length-1]
3232

3333
tmp := n.Right
3434
for tmp != nil {
35-
this.stack = append(this.stack, tmp)
35+
iterator.stack = append(iterator.stack, tmp)
3636
tmp = tmp.Left
3737
}
38-
this.length = len(this.stack)
38+
iterator.length = len(iterator.stack)
3939

4040
return n.Val
4141
}
4242

43-
/** @return whether we have a next smallest number */
44-
func (this *BSTIterator) HasNext() bool {
45-
if this.length != 0 {
43+
// HasNext return whether we have a next smallest number
44+
func (iterator *BSTIterator) HasNext() bool {
45+
if iterator.length != 0 {
4646
return true
4747
}
4848
return false

leetcode/0242.valid-anagram/valid_anagram.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import "reflect"
55
func IsAnagram(s string, t string) bool {
66
m, n := make(map[rune]int), make(map[rune]int)
77
for _, i := range s {
8-
m[i] += 1
8+
m[i]++
99
}
1010
for _, i := range t {
11-
n[i] += 1
11+
n[i]++
1212
}
1313
return reflect.DeepEqual(m, n)
1414
}

leetcode/0344.reverse-string/reverse_string.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package leetcode
22

33
func ReverseString(s []byte) {
44
length := len(s)
5-
for i := 0; i < length/2; i += 1 {
5+
for i := 0; i < length/2; i++ {
66
s[i], s[length-1-i] = s[length-1-i], s[i]
77
}
88
}

leetcode/0350.intersection-of-two-arrays-ii/intersection_of_two_arrays_ii.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ func Intersection(nums1 []int, nums2 []int) []int {
77
if _, exist := m[n]; !exist {
88
m[n] = 1
99
} else {
10-
m[n] += 1
10+
m[n]++
1111
}
1212
}
1313

1414
for _, n := range nums2 {
1515
if v, exist := m[n]; exist {
1616
if v != 0 {
1717
result = append(result, n)
18-
m[n] -= 1
18+
m[n]--
1919
}
2020
}
2121
}

leetcode/0384.shuffle-an-array/shuffle_an_array.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ func Constructor(nums []int) Solution {
1010
return Solution{nums}
1111
}
1212

13-
/** Resets the array to its original configuration and return it. */
14-
func (this *Solution) Reset() []int {
15-
return this.nums
13+
// Reset resets the array to its original configuration and return it.
14+
func (s *Solution) Reset() []int {
15+
return s.nums
1616
}
1717

18-
/** Returns a random shuffling of the array. */
19-
func (this *Solution) Shuffle() []int {
20-
nums := make([]int, len(this.nums))
21-
copy(nums, this.nums)
18+
// Shuffle returns a random shuffling of the array.
19+
func (s *Solution) Shuffle() []int {
20+
nums := make([]int, len(s.nums))
21+
copy(nums, s.nums)
2222
rand.Shuffle(len(nums), func(i int, j int) {
2323
nums[i], nums[j] = nums[j], nums[i]
2424
})

0 commit comments

Comments
 (0)