reverse-linked-list

This commit is contained in:
Gleb Koval 2022-06-04 23:46:41 +01:00
parent e028f4cf94
commit 4e9d897bd9
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
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
}