package main
import . "nc_tools"
/*
* type ListNode struct{
* Val int
* Next *ListNode
* }
*/
/**
*
* @param pHead ListNode类
* @return ListNode类
*/
//递归
func ReverseList( pHead *ListNode ) *ListNode {
if pHead == nil || pHead.Next == nil {
return pHead
}
last := ReverseList(pHead.Next)
pHead.Next.Next = pHead
pHead.Next = nil
return last
}
//迭代
func ReverseList( pHead *ListNode ) *ListNode {
if pHead == nil || pHead.Next == nil {
return pHead
}
var prev *ListNode
for pHead != nil {
curr := pHead
pHead = pHead.Next
curr.Next = prev
prev = curr
}
return prev
}