mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 08:27:30 +08:00
28 lines
424 B
Go
28 lines
424 B
Go
package leetcode
|
|
|
|
import (
|
|
"github.com/halfrost/LeetCode-Go/structures"
|
|
)
|
|
|
|
// ListNode define
|
|
type ListNode = structures.ListNode
|
|
|
|
/**
|
|
* Definition for singly-linked list.
|
|
* type ListNode struct {
|
|
* Val int
|
|
* Next *ListNode
|
|
* }
|
|
*/
|
|
|
|
func reverseList(head *ListNode) *ListNode {
|
|
var behind *ListNode
|
|
for head != nil {
|
|
next := head.Next
|
|
head.Next = behind
|
|
behind = head
|
|
head = next
|
|
}
|
|
return behind
|
|
}
|