why I Runtime error?Please instruct me.


  • 0
    Y
    class Solution {
    public:
        vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        vector<int> nums3;
        sort(nums1.begin(),nums1.end());
        sort(nums2.begin(),nums2.end());
        int n1=0,n2=0;
        while((n1<nums1.size()) || (n2<nums2.size()))
        {
            while(n1<nums1.size()-1 && nums1[n1]==nums1[n1+1])   ++n1;
            while(n2<nums2.size()-1 && nums2[n2]==nums2[n2+1])   ++n2;
            while(nums1[n1]==nums2[n2] && n1<nums1.size() && n2<nums2.size())
            {
                nums3.push_back(nums1[n1]);
                ++n1;
                ++n2;
            }
            while(nums1[n1]<nums2[n2] && n1<nums1.size())    n1++;
            while(nums1[n1]>nums2[n2] && n2<nums2.size())    n2++;
        }
        return nums3;
    }
    };
    

    I run ok in IDE(clion),but when submit,the result is "runtime error".
    could you instruct me? Thank you for your help.


Log in to reply
 

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