Golang 6ms iterative


  • 0
    R
    func reverseList(head *ListNode) *ListNode {
        var prev *ListNode
        curr := head
        for curr != nil {
            nextTemp := curr.Next
            curr.Next = prev
            prev = curr
            curr = nextTemp
        }
        return prev
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.