C# accepted solutiion


  • 0
    R
    		if (head == null || head.next == null) return head;
    		ListNode dummy1 = new ListNode(Int32.MinValue);
    		ListNode tail1 = dummy1;
    		ListNode dummy2 = new ListNode(Int32.MinValue);
    		ListNode tail2 = dummy2;
    
    		while (head != null)
    		{
    			if (head.val < x)
    			{
    				tail1.next = head;
    				head = head.next;
    				tail1 = tail1.next;
    				tail1.next = null;
    			}
    			else
    			{
    				tail2.next = head;
    				head = head.next;
    				tail2 = tail2.next;
    				tail2.next = null;
    			}
    		}
    		tail1.next = dummy2.next;
    		return dummy1.next;	
    		
    	}

Log in to reply
 

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