26 lines
325 B
Go
26 lines
325 B
Go
|
|
package main
|
||
|
|
|
||
|
|
type ListNode struct {
|
||
|
|
Val int
|
||
|
|
Next *ListNode
|
||
|
|
}
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
|
||
|
|
}
|
||
|
|
func reverseList(head *ListNode) *ListNode {
|
||
|
|
pre := (*ListNode)(nil)
|
||
|
|
res := (*ListNode)(nil)
|
||
|
|
for head != nil {
|
||
|
|
next := head.Next
|
||
|
|
head.Next = pre
|
||
|
|
pre = head
|
||
|
|
if next == nil {
|
||
|
|
res = head
|
||
|
|
break
|
||
|
|
}
|
||
|
|
head = next
|
||
|
|
}
|
||
|
|
return res
|
||
|
|
}
|