No matching function for call to ‘Solution::findMedianSortedArrays(std::vector<int>&, std::vector<int>&)’


  • 0
    C
    class Solution {
    public:
        static int findkth(int A[],int abeg,int aend,int B[],int bbeg,int bend,int k){
                if(abeg>aend) return B[bbeg+k-1];
                if(bbeg>bend) return A[abeg+k-1];
                int amid=abeg+(aend-abeg)/2;
                int bmid=bbeg+(bend-bbeg)/2;
                int halflen=amid-abeg+bmid-bbeg+2;
                if(A[amid]<B[bmid]){
                    if(halflen>k) return findkth(A,abeg,aend,B,bbeg,bmid-1,k);
                    else return findkth(A,amid+1,aend,B,bbeg,bend,k-(amid-abeg+1));
                }
                else{
                    if(halflen>k) return findkth(A,abeg,amid-1,B,bbeg,bend,k);
                    else return findkth(A,abeg,aend,B,bmid+1,bend,k-(bmid-bbeg+1));
                }
            }
        double findMedianSortedArrays(int A[], int m, int B[], int n) {
            if((m+n)%2) return findkth(A,0,m-1,B,0,n-1,(m+n)/2+1);
            else return (findkth(A,0,m-1,B,0,n-1,(m+n)/2)+findkth(A,0,m-1,B,0,n-1,(m+n)/2+1))*1.0/2;
        }
    };

  • 0
    S

    there is no function for vector<int>,but int[] ?


  • 0
    V

    I met this problem in another problem set too. For the first time, I admitted the code and it was accepted. However, the second time I admit the same code, notice that I don't make any changes, the system tells the similar compile error like yours. I think, it may be some bug of the system at a time.


  • 0
    C

    Yes,maybe you are right,because my code is accepted in compiler visual c++ 6.0.Thanks!


  • 0
    C

    Sorry,I don't understand.What 's the problem with my code?


  • 0
    S

    sorry,Im not quite sure about this


  • 0
    C

    You can change like this double findMedianSortedArrays(vector<int> &A,vector<int> &B),and also change int A[] into vector<int> &A in the called function.Then it will be accepted.I don't why.


  • 0
    C

    You can change like this double findMedianSortedArrays(vector &A,vector &B),and also change int A[] into vector &A in the called function.Then it will be accepted.I don't why.


Log in to reply
 

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