牛客-二維數組中的查找

牛客-二維數組中的查找

class Solution {
public:
    bool Find(int target, vector<vector<int> > array) {
        if (array.empty()) {
            return false;
        }
        int col = array[0].size();
        int row = array.size();
        for (int i=0; i<row; i++) {
            for (int j=col-1; j>=0; j--) {
                if (target == array[i][j]) {
                    return true;
                } else if (target>array[i][j]) {
                    break;
                } else {
                    continue;
                }
            }
        }
        
        return false;
    }
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章