Reverse Linked List Iterative


  • 0
    V

    public class Solution {
    public ListNode reverseList(ListNode head) {
    if(head == null){
    return head;
    }
    ListNode temp = null;

        ListNode node = null;
        
        while(head != null){
            node = head;
            head = head.next;
            node.next = temp;
            temp = node;
        }
        
        return node;
    }
    

    }


Log in to reply
 

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