题解 | #二维数组中的查找#

二维数组中的查找

https://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e

#include <iostream>
#include <vector>
using namespace std;
class Solution {
  public:
    bool Find(int target, vector<vector<int>> array) {
        int r = array.size();
        int c = array[0].size();
        for (int i = r - 1, j = 0; (i >= 0) && ( j < c); ) {
            cout << i << "" << j << endl;
            if (target == array[i][j]) {
                return true;
            } else if (target > array[i][j]) {
                j++;
            } else {
                i--;
            }

        }
        return false;
    }
};

全部评论

相关推荐

点赞 评论 收藏
分享
07-15 18:09
门头沟学院 Java
点赞 评论 收藏
分享
07-01 23:23
郑州大学 Java
否极泰来来来来:牛客迟早有高三的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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