Posted on

Description

Submission

class Solution {
public:
    int smallestCommonElement(vector<vector<int>>& mat) {
        int m = mat.size();
        int n = mat[0].size();

        for(int x: mat[0]) {
            int i = 1;
            for(; i < m; ++i) {
                auto iter = lower_bound(mat[i].begin(), mat[i].end(), x);
                if(*iter != x) break;
            }
            if(i == m) return x;
        }
        
        return -1;
        
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *