Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9e1be88

Browse files
1198. Find Smallest Common Element in All Rows
1 parent a17ba99 commit 9e1be88

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Runtime: 148 ms
2+
// Memory Usage: 28 MB
3+
class Solution {
4+
public:
5+
int smallestCommonElement(vector<vector<int>>& mat) {
6+
map<int, int> mp;
7+
for (auto A : mat) {
8+
for (int a : A) {
9+
mp[a]++;
10+
}
11+
}
12+
for (auto a : mp) {
13+
if (a.second == mat.size()) {
14+
return a.first;
15+
}
16+
}
17+
return -1;
18+
}
19+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /