problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::search_a_2d_matrix_ii::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static bool search (const vector< vector< int > > &matrix, int target, int x_start, int x_end, int y_start, int y_end)
 
static bool searchMatrix (vector< vector< int > > &matrix, int target)
 

详细描述

在文件 leetcode.h2596 行定义.

成员函数说明

◆ search()

bool leetcode::search_a_2d_matrix_ii::Solution::search ( const vector< vector< int > > &  matrix,
int  target,
int  x_start,
int  x_end,
int  y_start,
int  y_end 
)
static

在文件 leetcode.cpp6972 行定义.

6972 {
6973 const int minimum = min(x_end - x_start, y_end - y_start);
6974 vector<int> diag1(minimum + 1);
6975 for(int i = 0; i <= minimum; i++) {
6976 diag1[i] = matrix[x_start + i][y_start + i];
6977 }
6978 const auto it = lower_bound(diag1.begin(), diag1.end(), target);
6979 const int x = x_start + it - diag1.begin();
6980 const int y = y_start + it - diag1.begin();
6981 if(it != diag1.end()) {
6982 if(*it == target) {
6983 return true;
6984 }
6985 if(it == diag1.begin()) {
6986 return false;
6987 }
6988 if(search(matrix, target, x_start, x - 1, y, y_end)) {
6989 return true;
6990 }
6991 if(search(matrix, target, x, x_end, y_start, y - 1)) {
6992 return true;
6993 }
6994 if(search(matrix, target, x, x_end, y, y_end)) {
6995 return true;
6996 }
6997 } else {
6998 if(x > x_end && y > y_end) {
6999 return false;
7000 }
7001 if(x > x_end && search(matrix, target, x_start, x_end, y, y_end)) {
7002 return true;
7003 }
7004 if(y > y_end && search(matrix, target, x, x_end, y_start, y_end)) {
7005 return true;
7006 }
7007 }
7008 return false;
7009 }
static bool search(const vector< vector< int > > &matrix, int target, int x_start, int x_end, int y_start, int y_end)
Definition: leetcode.cpp:6972

引用了 search().

被这些函数引用 search() , 以及 searchMatrix().

◆ searchMatrix()

bool leetcode::search_a_2d_matrix_ii::Solution::searchMatrix ( vector< vector< int > > &  matrix,
int  target 
)
static

在文件 leetcode.cpp6970 行定义.

6970{ return search(matrix, target, 0, matrix.size() - 1, 0, matrix[0].size() - 1); }

引用了 search().

被这些函数引用 leetcode::search_a_2d_matrix_ii::TEST().


该类的文档由以下文件生成: