标签:tps sel ext element 调用 fun lis nts 实现
func reverseList(head *ListNode) *ListNode {
var pre *ListNode
cur := head
for cur != nil {
next := cur.Next
cur.Next = pre
pre = cur
cur = next
}
return pre
}
func reverseList(head *ListNode) *ListNode {
//1.递归结束
if head == nil || head.Next == nil{
return head
}
//2.递归主体
newHead := reverseList(head.Next)
head.Next.Next = head
head.Next = nil
return newHead
}
func removeElements(head *ListNode, val int) *ListNode {
dummyHead := &ListNode{}
dummyHead.Next = head
cur := dummyHead
for cur.Next != nil{
if cur.Next.Val == val{
cur.Next = cur.Next.Next
}else{
cur = cur.Next
}
}
return dummyHead.Next
}
func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
dummyHead := &ListNode{}
cur := dummyHead
for l1 != nil && l2 != nil{
if l1.Val <= l2.Val{
cur.Next = l1
cur = l1
l1 = l1.Next
}else{
cur.Next = l2
cur = l2
l2 = l2.Next
}
}
cur.Next = l1
if l1 == nil {
cur.Next = l2
}
return dummyHead.Next
}
标签:tps sel ext element 调用 fun lis nts 实现
原文地址:https://www.cnblogs.com/awesomeHai/p/12636648.html