public ListNode reverse(ListNode head){
    ListNode dummy = new ListNode(0);
    ListNode p = head;
    while(p != null){
        ListNode tmp = p;
        p = p.next;
        tmp.next = dummy.next;
        dummy.next = tmp;
    }
    return dummy.next;
}