Short C++ code with a quarterly search

  • 0
    class Solution {
        bool quadraSearch(int top,int bot,int left,int right,vector<vector<int>>& matrix,int target)
            if (top>bot || left>right) return false;
            if (matrix[top][left]>target || matrix[bot][right]<target) return false;
            if (bot==top && right==left) return true;
            int midr = top+bot>>1;
            int midc = left+right>>1;
            return quadraSearch(top,mi`enter code here`dr,left,midc,matrix,target) || 
                   quadraSearch(midr+1,bot,left,midc,matrix,target) || 
                   quadraSearch(top,midr,midc+1,right,matrix,target) ||
        bool searchMatrix(vector<vector<int>>& matrix, int target) {
            return quadraSearch(0,matrix.size()-1,0,matrix[0].size()-1,matrix,target);

Log in to reply

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