题解 | #矩阵元素查找#

矩阵元素查找

http://www.nowcoder.com/practice/3afe6fabdb2c46ed98f06cfd9a20f2ce

class Solution {
public:
vector<int> findElement(vector<vector<int> > mat, int n, int m, int x) {
// write code here
int i=0,j=m-1;
vector<int> ret;
while(i<n && j>=0) {
if(mat[i][j] == x) {
ret.push_back(i);
ret.push_back(j);
break;
}
else if(mat[i][j] > x) {
j--;
}
else {
i++;
}
}
return ret;
}
};</int></int></int>

全部评论

相关推荐

评论
2
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务