题解 | #矩阵元素查找#

矩阵元素查找

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> res;
        int i = 0, j = m-1;
        while(i<n && j>=0){
            if(mat[i][j] == x){
                res.push_back(i);
                res.push_back(j);
                break;
            }
            else if(mat[i][j] < x){
                i++;
            }
            else{
                j--;
            }
        }
        return res;
    }
};
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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