-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMedianOfTwoSortedArrays.java
More file actions
59 lines (46 loc) · 1.17 KB
/
Copy pathMedianOfTwoSortedArrays.java
File metadata and controls
59 lines (46 loc) · 1.17 KB
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
51
52
53
54
55
56
57
58
59
/**
* MedianOfTwoSortedArrays
*/
public class MedianOfTwoSortedArrays {
}
class Solution {
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
int n = nums1.length;
int m = nums2.length;
int mid = (n + m ) / 2;
if (n == 0) {
if (m == 1) {
return nums2[0];
}
else if (m % 2 == 0) {
return (nums2[m/2] + nums2[m/2+1] / 2);
}
else {
return nums2[m/2];
}
}
else if (m == 0) {
if (n == 1) {
return nums2[0];
}
else if (n % 2 == 0) {
return (nums2[n/2] + nums2[n/2+1] / 2);
}
else {
return nums2[n/2];
}
}
int start = n / 2;
int end = m / 2;
// Even case
if (mid % 2 == 0) {
}
else if (mid % 2 != 0) { // remove if
while (start != end) {
mid = start + (end - start) / 2;
if (condition) {
}
}
}
}
}