Easy understanding C++ 12ms Solution (using STL)


  • -2
    O
    class Solution 
    {
    public:
       bool searchMatrix(vector<vector<int>>& matrix, int target) 
        {
        vector<int> matrix_in_one_row;
        for (int i = 0; i < matrix.size(); ++i)
            matrix_in_one_row.insert(matrix_in_one_row.end(), matrix[i].begin(), matrix[i].end());
        if (std::binary_search (matrix_in_one_row.begin(), matrix_in_one_row.end(), target))
            return true;
        else 
            return false;
        }
    };

Log in to reply
 

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