题解 | #矩阵元素查找#

矩阵元素查找

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
        vector<int> A;
        if(mat.size()<=0||mat[0].size()<=0)
        return A;
        int i=n-1,j=0;//从左下角开始查找x
        while(i>=0&&j<m){
            if(mat[i][j]==x){
                A.push_back(i);
                A.push_back(j);
                return A;
            }
            else if(x>mat[i][j]){
                j++;
            }
            else i--;
        }
        return A;
    }
};
全部评论

相关推荐

求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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