Simple ruby solution


  • 0
    N
    def reverse_list(head)
        if not head
            return head
        end
        
        prev = head
        current = head.next
        prev.next = nil
        
        while current
            tmp = current.next
            current.next = prev
            prev = current
            current = tmp
        end
        return prev
    end

Log in to reply
 

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