Merge pull request #60 from halfrost/code_quality_improvement

optimization code quality level from A to A+
This commit is contained in:
halfrost
2020-08-27 01:07:57 +08:00
committed by YDZ
543 changed files with 2449 additions and 2396 deletions

View File

@ -19,11 +19,9 @@ func insertionSortList(head *ListNode) *ListNode {
return head
}
newHead := &ListNode{Val: 0, Next: nil} // 这里初始化不要直接指向 head为了下面循环可以统一处理
cur := head
pre := newHead
next := &ListNode{Val: 0, Next: nil}
cur, pre := head, newHead
for cur != nil {
next = cur.Next
next := cur.Next
for pre.Next != nil && pre.Next.Val < cur.Val {
pre = pre.Next
}

View File

@ -28,21 +28,21 @@ func Test_Problem147(t *testing.T) {
qs := []question147{
question147{
{
para147{[]int{4, 2, 1, 3}},
ans147{[]int{1, 2, 3, 4}},
},
question147{
{
para147{[]int{1}},
ans147{[]int{1}},
},
question147{
{
para147{[]int{-1, 5, 3, 4, 0}},
ans147{[]int{-1, 0, 3, 4, 5}},
},
question147{
{
para147{[]int{}},
ans147{[]int{}},
},