package main
import . "nc_tools"
/*
* type ListNode struct{
* Val int
* Next *ListNode
* }
*/
/**
*
* @param pHead ListNode类
* @return ListNode类
*/
func ReverseList( pHead *ListNode ) *ListNode {
// write code here
if pHead==nil || pHead.Next==nil{
return pHead
}
var newHead *ListNode
for pHead!=nil{
pNext:=pHead.Next
pHead.Next=newHead
newHead=pHead
pHead=pNext
}
return newHead
}
GO语言:反转链表
最新推荐文章于 2024-03-19 13:13:11 发布