leet-code/reverse-linked-list/sol.go

26 lines
387 B
Go
Raw Normal View History

2022-06-04 22:46:41 +00:00
package main
type ListNode struct {
Val int
Next *ListNode
}
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func reverseList(head *ListNode) *ListNode {
var last *ListNode = nil
current := head
for current != nil {
next := current.Next
current.Next = last
last = current
current = next
}
return last
}