示例#1
0
文件: median.c 项目: Sasasu/leetcode
double findMedianSortedArrays(int* nums1, int l1, int* nums2, int l2) 
{
	if (!l1 && !l2) return 0.0;
	int m1, m2;
	int *p1, *p2;
	m1 = (l1 + l2 - 1) / 2;
	m2 = m1;
	if ((l1 + l2) % 2 == 0)
		m2 += 1;
	p1 = findmid(nums1, l1, nums2, l2, m1);
	if (!p1)
		p1 = findmid(nums2, l2, nums1, l1, m1);
		
	p2 = findmid(nums1, l1, nums2, l2, m2);
	if (!p2)
		p2 = findmid(nums2, l2, nums1, l1, m2);
	return 1.0 * (*p1 + *p2) / 2;
}
示例#2
0
 ListNode *sortList(ListNode *head) {
     if (head == NULL || head -> next == NULL) {
         return head;
     }
     ListNode *mid = findmid(head);
     ListNode *right = sortList(mid -> next);
     mid -> next = NULL;
     ListNode *left = sortList(head);
     return sortList_merge(left, right);
 }