Skip to content

Fix 0101.孤岛的总面积.md C++的dfs代码问题 #2960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jay-Chou118
Copy link

这道题目的意思应该是计算孤岛个数吧,根据题意,
对于
5 6
1 1 0 0 0 0
1 1 0 0 0 0
0 0 1 1 0 0
0 0 0 0 0 1
0 0 0 0 0 0
这个输入,应该输出是1.
但是按照卡哥的代码,输出会是2,问题就出在应该是找到grid[i][j]==1的陆地后,继续进行dfs,而不是直接count++ 我这边是只修改dfs的部分,还没修改bfs 的部分

这道题目的意思应该是计算孤岛个数吧,根据题意,
对于
5 6
1 1 0 0 0 0
1 1 0 0 0 0
0 0 1 1 0 0
0 0 0 0 0 1
0 0 0 0 0 0
这个输入,应该输出是1.
但是按照卡哥的代码,输出会是2,问题就出在应该是找到==1的陆地后,继续进行dfs,而不是直接count++
我这边是只修改dfs的部分,还没修改bfs 的部分
@Jay-Chou118 Jay-Chou118 changed the title Update 0101.孤岛的总面积.md Fix 0101.孤岛的总面积.md C++的dfs代码问题 Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant