题解 | #矩阵元素查找#

矩阵元素查找

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;
    }
};
全部评论

相关推荐

07-23 11:37
延安大学 C++
绷不住了,晚上十点发拒信,是还在加班吗这样一想挂了好像也没什么不好
码农索隆:这个都是真人发嘛,会用到机器人定时发嘛
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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