Submission Detail

2094 / 2094 test cases passed.
Status:

Accepted

Runtime: 12 ms
Memory Usage: 6.4 MB
Submitted: 0 minutes ago

Accepted Solutions Runtime Distribution

0
5
10
15
20
25
30
35
40
45
50
55
60
65
70
5
10
15
20
25
30
c
You are here!
Your runtime beats 82.90 % of c submissions.
Runtime (ms)
Distribution (%)

0
5
10
15
20
25
30
35
40
45
50
55
60
65
70
10
20
30
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

6600
6200
6300
6400
6500
6700
6800
6900
7000
5
10
15
20
c
You are here!
Your memory usage beats 72.30 % of c submissions.
Memory (KB)
Distribution (%)

6600
6200
6300
6400
6500
6700
6800
6900
7000
10
20
Zoom area by dragging across this chart

Invite friends to challenge Median of Two Sorted Arrays


Submitted Code: 0 minutes ago

Language: c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
double findKthSortedArrays(int *nums1, int nums1Size, int *nums2, int nums2Size, int kth)
{
if (nums1Size == 0)
{
return nums2[kth - 1];
}
if (nums2Size == 0)
{
return nums1[kth - 1];
}
if (kth == 1)
{
return nums2[0] > nums1[0] ? nums1[0] : nums2[0];
}
int kth_left_half = kth / 2;
int kth_right_half = kth / 2;
if (nums1Size < kth_left_half)
{
kth_left_half = nums1Size;
}
if (nums2Size < kth_right_half)
{
kth_right_half = nums2Size;
}
if (nums1[kth_left_half - 1] <= nums2[kth_right_half - 1])
{
nums1 += kth_left_half;
nums1Size -= kth_left_half;
kth -= kth_left_half;
}
else if (nums1[kth_left_half - 1] > nums2[kth_right_half - 1])
{
nums2 += kth_right_half;
nums2Size -= kth_right_half;
kth -= kth_right_half;
}
return findKthSortedArrays(nums1, nums1Size, nums2, nums2Size, kth);
}
double findMedianSortedArrays(int *nums1, int nums1Size, int *nums2, int nums2Size)
{
// find (nums1Size+nums2Size)/2 th num
int left_kth = (nums1Size+nums2Size+1)/2;
int right_kth = (nums1Size+nums2Size+2)/2;
return (findKthSortedArrays(nums1,nums1Size,nums2,nums2Size,left_kth)+
findKthSortedArrays(nums1,nums1Size,nums2,nums2Size,right_kth))/2.0;
}