public ListNode reverseList(ListNode head) {

   if(head==null)

   return null;

    ListNode p1 = head;

    ListNode p2 = p1.next;

     head.next = null;

     while(p1!=null&&p2!=null){

         ListNode tmp = p2.next;

         p2.next = p1;

         p1 = p2;

         p2 = tmp;

     }return p1;

}

results matching ""

    No results matching ""