Reverse a linked list

  • + 0 comments

    Java Solution:

        public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) {
        
            SinglyLinkedListNode current = llist;
            SinglyLinkedListNode pre = null;
    
            while(current != null){
                SinglyLinkedListNode next = current.next;
                current.next = pre;
                pre = current;
                current = next;
            }
            return pre;
            
        }