Why run time error?


  • 0
    R

    [[-1],[-1]], -2 Run time error
    But it works in Eclipse

    class Solution {
    public:
        bool searchPart(vector<vector<int>>& matrix, int target, int left, int right, int top, int bottom){
            if(top==bottom||left==right)
                return false;
            int y = (right-left)/2;
            int x = (top-bottom)/2;
            if(target == matrix[x][y])
                return true;
            else if(target<matrix[x][y])
                return searchPart(matrix,target,left,y,top,bottom)||searchPart(matrix,target,y,y+1,top,x);
            else 
                return searchPart(matrix,target,y+1,right,top,bottom)||searchPart(matrix,target,y,y+1,x+1,bottom);
        }
        
        bool searchMatrix(vector<vector<int>>& matrix, int target) {
            int rows = matrix.size();
            if(rows==0)
                return false;
            int cols = matrix[0].size();
            return searchPart(matrix,target,0,cols,0,rows);
        }
    };

  • 0
    L

    Maybe you need to use :

      int y = left + (right-left)/2;
        int x = bottom + (top-bottom)/2;

Log in to reply
 

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