class Solution {

public:

```
int median(int a[], int n) {
if (a==NULL || n==0) return -1;
if (n==1) return a[0];
if (n%2 == 0) return (a[n/2-1] + a[n/2])/2;
else return a[n/2];
}
//My guess is it means my program does not handle the first array input correctly when it pass NULL through
//unknown sized array parameter. Should I return -1 or zero if it is NULL?
double findMedianSortedArrays(int A[], int m, int B[], int n) {
if ((!A || m<=0) && (!B || n<=0)) return -1;
if (A!=NULL && m==1 && B!=NULL && n==1) return (A[0]+B[0])/2;
int mA, mB;
mA = median(A, m);
mB = median(B, n);
if (mA==mB) return mA;
if (mA < mB)
return findMedianSortedArrays(A+m-(m/2+1), m/2+1, B, n/2+1);
else
return findMedianSortedArrays(A, m/2+1, B+n-(n/2+1), n/2+1);
}
```

};