//遞歸合併兩個單鏈表 public static Node mergeSortedRec(Node head1, Node head2){ if(head1 == null){ return head2; } if(head2 == null){ return head1; } Node mergeHead = null; if(head1.val < head2.val){ mergehead = head1; // 已解決的子問題 mergeHead.next = mergeSortedRec(head1.next,head2); }else{ mergeHead = head2; //已解決的子問題 mergeHead.next = mergeSortedRec(head1,head2.next); } return mergeHead; }