← 返回 sofi 的题目列表LeetCode 1198 — Find Smallest Common Element in All Rows
类型:online_judge
Given an m x n integer matrix mat where each row is sorted in non-decreasing order, find the smallest integer that appears in every row.
Return the smallest such integer if it exists.
Return -1 if no integer appears in all rows.
I/O Contract
Input: 2D integer array mat
Output: a single integer
Constraints
1 <= m, n <= 500
1 <= mat[i][j] <= 10^4
Each row of mat is sorted in non-decreasing order.
Examples
mat = [[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]] => 5
mat = [[1,2,3],[4,5,6]] => -1
Interview note: you are expected to clarify edge cases and write your own test methods and test cases.
Example
Input
[[1,2,3,4,5],[2,4,5,8,10],[3,5,7,9,11],[1,3,5,7,9]]
Output
5