/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func reverseList(head *ListNode) *ListNode {
var pre *ListNode = nil
for {
if head == nil {
break
}
tmp := head.Next
head.Next = pre
pre = head
head = tmp
}
return pre
}
golang leetcode reverse Linked List
最新推荐文章于 2023-11-14 10:34:30 发布