题解 | #矩阵元素查找#

矩阵元素查找

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

class Solution {
public:

    vector<int> findElement(vector<vector<int> >& mat, int n, int m, int x) {        
    vector<int> res(2);
    for (int i = 0; i < n; i++) {
      if(mat[i][0] <= x && mat[i][m -1] >= x){
           for(int j = 0; j < m; j++){
            if(mat[i][j] == x){
                res[0] = i;
                res[1] = j;
                return res;
            }
           }
      }
    }
        
      
      return res;      
   
}
    
};

全部评论

相关推荐

UtopianYou...:这个简历排版真的不太行哦,去找免费的或者花点小钱,把排版弄整齐一点吧,看着舒服。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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