Runtime Error ,reference binding to null pointer of type 'value_type'


  • 0
    L

    Last executed inputs are
    [2]
    []
    but it work on xcode and online
    the complexity is O(m+n) :( but i want to know where does the error come from
    0_1492180130470_2333.png
    here's my code :

    class Solution {
    public:
    double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {

        int size1 = (int)nums1.size();
        int size2 = (int)nums2.size();
        
        vector<int> result;
        int i,j = 0;
        while (i<size1 && j<size2) {
            if (nums1[i] == nums2[j]) {
                result.push_back(nums1[i]);
                i++;
                j++;
            }else if(nums1[i] < nums2[j]){
                result.push_back(nums1[i]);
                i++;
            }else if (nums1[i] > nums2[j]){
                result.push_back(nums2[j]);
                j++;
            }
        }
        while (i<size1) {
            result.push_back(nums1[i]);
            i++;
        }
        while (j<size2) {
            result.push_back(nums2[j]);
            j++;
        }
        if (result.size()%2 != 0) {
            return result[(int)(result.size()/2)];
            
        }else{
            if (result.size() == 1) {
                return result[0];
            }else{
                int temp = (int)result.size()/2;
                return 0.5*(result[temp] + result[temp-1]);
            }
        }
    }
    

    };


  • 0
    L
    This post is deleted!

Log in to reply
 

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