easy to understand,java, 0ms


  • 0
    N
      ListNode curr=new ListNode(0);
          curr=head;
          int count=0;
          while(curr!=null){
          	count++;
          	curr=curr.next;
          	
          }
          
          curr=head;
          int[] vals=new int[count];
          for(int i=0;i<count;i++){
          	vals[i]=curr.val;
          	curr=curr.next;
          }
         
          curr=head;
          
          for(int i=count-1;i>=0;i--){
          	
          	curr.val=vals[i];
          	curr=curr.next;
          }
          return head;

Log in to reply
 

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