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

#include <leetcode.h>

静态 Public 成员函数

static int maxAreaOfIsland (vector< vector< int > > &grid)
 

详细描述

在文件 leetcode.h1682 行定义.

成员函数说明

◆ maxAreaOfIsland()

int leetcode::max_area_of_island::Solution::maxAreaOfIsland ( vector< vector< int > > &  grid)
static

在文件 leetcode.cpp4227 行定义.

4227 {
4228 const int m = grid.size();
4229 const int n = grid[0].size();
4230 auto uf = UnionFind(m, n);
4231 int ans = 0;
4232 for(int i = 0; i < m; i++) {
4233 for(int j = 0; j < n; j++) {
4234 if(grid[i][j] == 1) {
4235 const pair<int, int> p = make_pair(i, j);
4236 ans = max(ans, uf.get_size(p));
4237 pair<int, int> siblings[4] = {
4238 make_pair(i + 1, j),
4239 make_pair(i - 1, j),
4240 make_pair(i, j + 1),
4241 make_pair(i, j - 1),
4242 };
4243 for(const auto sibling: siblings) {
4244 if(uf.contains(sibling) && grid[sibling.first][sibling.second] == 1 && !uf.same(p, sibling)) {
4245 uf.merge(p, sibling);
4246 ans = max(ans, uf.get_size(p));
4247 }
4248 }
4249 }
4250 }
4251 }
4252 return ans;
4253 }
并查集
Definition: templates.h:91

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


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