class Solution { ListNode p1 ; public ListNode reverseList(ListNode head) { ListNode p = head; while(p!=null){ addFirst(p.val); p = p.next; } return p1; } void addFirst(int a){ ListNode renode=new ListNode(a); if(p1!=null){ renode.next = p1; } p1 = renode; } }