reverse-linked-list
This commit is contained in:
parent
e028f4cf94
commit
4e9d897bd9
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue