牛客题霸NC78 反转链表题解
反转链表
https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca?tpId=190&&tqId=35203&rp=1&ru=/activity/oj&qru=/ta/job-code-high-rd/question-ranking
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 {
return nil
}
VirtualRoot := &ListNode{Val: 0}
VirtualRoot.Next = pHead
start := VirtualRoot.Next
next := start.Next
for next != nil {
start.Next = next.Next
next.Next = VirtualRoot.Next
VirtualRoot.Next = next
next = start.Next
}
return VirtualRoot.Next
// write code here
}