240. Search a 2D Matrix II [ C++] three approach best and concise -
240. Search a 2D Matrix II\n\n\n\n\n\n\n\n\nclass Solution {\npublic:\n    bool searchMatrix(vector<vector<int>>& matrix, int target)\n    {\n        int n = ma
**240. Search a 2D Matrix II**\n\n![image](https://assets.leetcode.com/users/images/5282d569-2c24-4068-9179-fa4fdd7617be_1658655205.7487211.jpeg)\n![image](https://assets.leetcode.com/users/images/37279826-90a1-40f7-82bf-1e520ef617e2_1658655283.2490494.jpeg)\n\n\n\n\n```\nclass Solution {\npublic:\n    bool searchMatrix(vector<vector<int>>& matrix, int target)\n    {\n        int n = matrix.size();\n        int m = matrix[0].size();\n        // start from the [last row, first column] element\n        int i = n - 1;\n        //set j to \'0\' initially\n        int j = 0;\n        while (j < m && i >= 0)\n        {\n            //if target is found\n            if (matrix[i][j] == target)\n            {\n                return true;\n            }\n            //in else if we checj that target is less than matrix value\n            else if (matrix[i][j] > target)\n            {\n                --i;\n                // decrease the row index\n            }\n            else\n            {\n                ++j;\n                // increase the column index\n            }\n        }\n        return false;\n        // target not found\n        // return false\n    }\n};\n\n```
['C', 'Binary Tree']