Can anyone help me to find the "StackOverFlowError" of my answer?

  • 1
    public ListNode sortList(ListNode head) {
    	if(head==null){ return null;}
    	if({ return head;}
    	ListNode mid = getMid(head);
    	ListNode fharf =head;
    	return merge2Lists(sortList(fharf),sortList(sharf));
    public ListNode getMid(ListNode head){
    	if(head==null) {return head;}
    	if( return head;
    	ListNode slow=head;
    	ListNode fast = head;
    	return slow;
     public ListNode merge2Lists(ListNode a, ListNode b) {
        ListNode dummyHead, curr; 
        curr = dummyHead;
        while(a !=null && b!= null) {
            if(a.val <= b.val) { = a; a =; }
            else { = b; b =; }
            curr =;
        } = (a == null) ? b : a;

  • 0

    I don't understand why this question is closed. Basically the po got StackOverFlowError after submitting his/her code and wanted to know where the unnecessary space usage come from.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.