1
我無法找到任何代碼錯誤,但是當我提交它時,兩個測試用例給運行時錯誤。請幫我弄清楚這個錯誤。我已經檢查了至少30個自定義測試用例,但它爲所有用戶提供了正確的輸出。遞歸合併兩個已排序的鏈表?
Code
public static Node mergeTwoList(Node head1, Node head2) {
Node c = null;
if (head1 == null) {
return head2;
} else if (head2 == null) {
return head1;
}
if (head1.data < head2.data) {
c = head1;
c.next = mergeTwoList(head1.next, head2);
} else {
c = head2;
c.next = mergeTwoList(head1, head2.next);
}
return c;
}
如果有人想出什麼請你告訴我。
什麼是錯誤? –
在線工具沒有提供具體的細節。它只是顯示運行時錯誤 –
@KillerDeath可能是由於遞歸導致的堆棧溢出。你找到了什麼? –