Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed kokeunho/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
| 29μ°¨μ‹œ | 2025.07.21 | κ·Έλž˜ν”„ 탐색 | [뢈!](https://www.acmicpc.net/problem/4179) |[#118](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/118) |
| 30μ°¨μ‹œ | 2025.07.26 | κ·Έλž˜ν”„ 탐색 | [μ€‘λŸ‰μ œν•œ](https://www.acmicpc.net/problem/1939) |[#120](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/120) |
| 31μ°¨μ‹œ | 2025.08.03 | κ·Έλž˜ν”„ 탐색 | [λ©΄μ ‘λ³΄λŠ” μŠΉλ²”μ΄λ„€](https://www.acmicpc.net/problem/17835) | [#126](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/126) |
| 32μ°¨μ‹œ | 2025.08.10 | κ·Έλž˜ν”„ 탐색 | [μ„μœ  μ‹œμΆ”](https://school.programmers.co.kr/learn/courses/30/lessons/250136) |[#129](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/129) |
---
57 changes: 57 additions & 0 deletions kokeunho/κ·Έλž˜ν”„ 탐색/32-kokeunho.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import java.util.*;

class Solution {
static int col, row;
static int[] dx = {-1, 1, 0, 0};
static int[] dy = {0, 0, -1, 1};
static int[] sumAreaPerCol;
static boolean[][] visited;

public int solution(int[][] land) {
col = land[0].length;
row = land.length;
sumAreaPerCol = new int[col];
visited = new boolean[row][col];

for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
if (land[j][i] == 1 && !visited[j][i]) {
bfs(j, i, land);
}
}
}

int maxArea = 0;
for (int i = 0; i < col; i++) {
maxArea = Math.max(maxArea, sumAreaPerCol[i]);
}
return maxArea;
}
public void bfs(int x, int y, int[][] land) {
Queue<int[]> queue = new LinkedList<>();
queue.add(new int[]{x, y});
visited[x][y] = true;
int area = 1;
Set<Integer> colList = new HashSet<>();
colList.add(y);

while(!queue.isEmpty()) {
int[] current = queue.poll();

for (int i = 0; i < 4; i++) {
int nx = current[0] + dx[i];
int ny = current[1] + dy[i];
if (nx >= 0 && nx < row && ny >= 0 && ny < col && !visited[nx][ny] && land[nx][ny] == 1) {
queue.add(new int[]{nx, ny});
visited[nx][ny] = true;
area++;
colList.add(ny);
}
}
}

for (int column : colList) {
sumAreaPerCol[column] += area;
}
}
}