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

#include <leetcode.h>

静态 Public 成员函数

static bool checkValid (vector< vector< int > > &matrix)
 

详细描述

在文件 leetcode.h284 行定义.

成员函数说明

◆ checkValid()

bool leetcode::check_if_every_row_and_column_contains_all_numbers::Solution::checkValid ( vector< vector< int > > &  matrix)
static

在文件 leetcode.cpp625 行定义.

625 {
626 const unsigned int n = matrix.size();
627 for(int i = 0; i < n; i++) {
628 auto *const row = new bool[n + 1];
629 memset(row, 1, (n + 1) * sizeof(bool));
630 for(int j = 0; j < n; j++) {
631 if(!row[matrix[i][j]]) {
632 delete[] row;
633 return false;
634 }
635 row[matrix[i][j]] = false;
636 }
637 delete[] row;
638 }
639
640 for(int j = 0; j < n; j++) {
641 auto *const column = new bool[n + 1];
642 memset(column, 1, (n + 1) * sizeof(bool));
643 for(int i = 0; i < n; i++) {
644 if(!column[matrix[i][j]]) {
645 delete[] column;
646 return false;
647 }
648 column[matrix[i][j]] = false;
649 }
650 delete[] column;
651 }
652 return true;
653 }

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