增加新题目
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type ListNode struct {
|
||||
Val int
|
||||
Next *ListNode
|
||||
@@ -11,10 +13,59 @@ func main() {
|
||||
func mergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {
|
||||
upP := list1
|
||||
dnP := list2
|
||||
for upP.Next != nil && dnP.Next != nil {
|
||||
if upP.Next == nil {
|
||||
|
||||
firstNode := (*ListNode)(nil)
|
||||
value := 0
|
||||
Ponit := (*ListNode)(nil)
|
||||
if list1 == nil {
|
||||
if list2 == nil {
|
||||
return nil
|
||||
}
|
||||
return list2
|
||||
|
||||
}
|
||||
return nil
|
||||
if list2 == nil {
|
||||
return list1
|
||||
}
|
||||
for upP != nil || dnP != nil {
|
||||
tmpP := &ListNode{}
|
||||
|
||||
if upP == nil {
|
||||
tmpP.Val = dnP.Val
|
||||
Ponit.Next = tmpP
|
||||
dnP = dnP.Next
|
||||
|
||||
Ponit = Ponit.Next
|
||||
fmt.Println("停留1")
|
||||
continue
|
||||
}
|
||||
if dnP == nil {
|
||||
tmpP.Val = upP.Val
|
||||
Ponit.Next = tmpP
|
||||
upP = upP.Next
|
||||
|
||||
Ponit = Ponit.Next
|
||||
fmt.Println("停留2")
|
||||
continue
|
||||
}
|
||||
if upP.Val >= dnP.Val {
|
||||
tmpP.Val = dnP.Val
|
||||
dnP = dnP.Next
|
||||
} else {
|
||||
tmpP.Val = upP.Val
|
||||
upP = upP.Next
|
||||
}
|
||||
|
||||
if value == 0 {
|
||||
Ponit = tmpP
|
||||
firstNode = Ponit
|
||||
value++
|
||||
continue
|
||||
}
|
||||
Ponit.Next = tmpP
|
||||
Ponit = Ponit.Next
|
||||
|
||||
value++
|
||||
|
||||
}
|
||||
return firstNode
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user