Does anyone know why this doesn't work?


  • -1
    J

    '''
    /**

    • Definition for singly-linked list.

    • public class ListNode {

    • int val;
      
    • ListNode next;
      
    • ListNode(int x) { val = x; }
      
    • }
      */
      public class Solution {
      public ListNode reverseList(ListNode head) {

       //if (head == null )
       //    return head;
           
       ListNode curr = null;
       ListNode lst = null;
       while (head != null)
       {
           curr = head;
           curr.next = lst;
           lst = curr;
           head = head.next;
      
        }
        
        return curr;
        
    }
    

    }'''


Log in to reply
 

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