2 lines 12ms C++ solution using std binary search functions


  • 0
    T
    class Solution {
    public:
        bool searchMatrix(vector<vector<int>>& matrix, int target) {
            auto it = upper_bound(matrix.begin(),matrix.end(), target, [](int t, vector<int>& v){return t < v[0];}) - 1;
            return it != matrix.begin() - 1 && binary_search(it->begin(), it->end(), target);
        }
    };

Log in to reply
 

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