Can anyone help with the error?


  • 0
    Z

    Runtime Error Message:
    reference binding to misaligned address 0x00000000000b for type 'value_type', which requires 4 byte alignment
    Last executed input:
    [2,2,2,2]
    [2,2,2]

    '''
    class Solution {

    public:
    double findKthNum(vector<int>* nums1, vector<int>* nums2, int len1, int len2, int k){
    if(len1==0) return double((*nums2)[k-1]);
    if(len2==0) return double((*nums1)[k-1]);

        int i = len1/2, j = len2/2;
        
        if((*nums1)[i]<=(*nums2)[j]){
            if(i+j+1<k){
                return findKthNum(nums1+i+1, nums2, len1-i-1, len2, k-i-1);
            }
            else{
                return findKthNum(nums1, nums2, len1, j, k);
            }
        }
        else{
            if(i+j+1<k){
                return findKthNum(nums1, nums2+j+1, len1, len2-j-1, k-j-1);
            }
            else{
                return findKthNum(nums1, nums2, len1, j, k);
            }            
        }        
    };
    
    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
    
        int len1 = nums1.size();
        int len2 = nums2.size();
        int mid = (len1 + len2)/2;
        
        if ((len1 + len2)%2){ // odd total length
            double mediannum = findKthNum(&nums1, &nums2, len1, len2, mid+1); 
            return mediannum;
        }
        else{
            double mediannum1 = findKthNum(&nums1, &nums2, len1, len2, mid);
            double mediannum2 = findKthNum(&nums1, &nums2, len1, len2, mid+1);
            return (mediannum1 + mediannum2)/2;
        }
    };
    

    };
    '''


Log in to reply
 

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