#include <leetcode.h>
|
static constexpr int | dirs [4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}} |
|
◆ longestIncreasingPath()
int leetcode::longest_increasing_path_in_a_matrix::Solution::longestIncreasingPath |
( |
vector< vector< int > > & |
matrix | ) |
|
在文件 leetcode.cpp 第 9066 行定义.
9067 if(matrix.empty() || matrix[0].empty()) {
9070 rows = matrix.size();
9072 auto outdegrees = vector(
rows, vector<int>(
columns));
9073 for(
int i = 0; i <
rows; ++i) {
9074 for(
int j = 0; j <
columns; ++j) {
9075 for(
int k = 0; k < 4; ++k) {
9076 const int newRow = i +
dirs[k][0], newColumn = j +
dirs[k][1];
9077 if(newRow >= 0 && newRow < rows && newColumn >= 0 && newColumn <
columns && matrix[newRow][newColumn] > matrix[i][j]) {
9083 queue<pair<int, int>> q;
9084 for(
int i = 0; i <
rows; ++i) {
9085 for(
int j = 0; j <
columns; ++j) {
9086 if(outdegrees[i][j] == 0) {
9094 const int size = q.size();
9095 for(
int i = 0; i < size; ++i) {
9096 const auto cell = q.front();
9098 const int row = cell.first, column = cell.second;
9099 for(
int k = 0; k < 4; ++k) {
9100 int newRow = row +
dirs[k][0], newColumn = column +
dirs[k][1];
9101 if(newRow >= 0 && newRow < rows && newColumn >= 0 && newColumn <
columns && matrix[newRow][newColumn] < matrix[row][column]) {
9102 --outdegrees[newRow][newColumn];
9103 if(outdegrees[newRow][newColumn] == 0) {
9104 q.push({newRow, newColumn});
static constexpr int dirs[4][2]
引用了 columns, dirs , 以及 rows.
◆ columns
int leetcode::longest_increasing_path_in_a_matrix::Solution::columns |
◆ dirs
constexpr int leetcode::longest_increasing_path_in_a_matrix::Solution::dirs[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}} |
|
staticconstexpr |
◆ rows
int leetcode::longest_increasing_path_in_a_matrix::Solution::rows |
该类的文档由以下文件生成: