Reverse Linked List
Solution in go
func reverseList(head *ListNode) *ListNode {
    if head == nil || head.Next == nil {
        return head
    }

    current := head
    var previous *ListNode

    for current != nil {
        next := current.Next
        current.Next = previous
        previous = current
        current = next
    }

    return previous
}
    TheDeveloperCafe © 2022-2024