1. ๋ฌธ์ :https://school.programmers.co.kr/learn/courses/30/lessons/17679
2. ํ์ด
๋ฌธ์ ์์๋๋ก ํ์ดํจ
3. ์ฝ๋
class Solution {
public int solution(int m, int n, String[] board) {
int answer = 0;
boolean[][] ch = new boolean[m][n];
char[][] boardd = new char[m][n];
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
boardd[i][j] = board[i].charAt(j);
}
}
while(true){
int temp = answer;
for(int i=0; i<m-1; i++){
for(int j=0; j<n-1; j++){
if(boardd[i][j] == boardd[i][j+1] &&
boardd[i][j] == boardd[i+1][j] &&
boardd[i][j] == boardd[i+1][j+1] &&
boardd[i][j] != '0'){
ch[i][j] = true;
ch[i][j+1] = true;
ch[i+1][j] = true;
ch[i+1][j+1] = true;
}
}
}
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(ch[i][j]){
answer++;
boardd[i][j] = '0';
}
}
}
if(temp == answer) break;
boolean[][] bt = new boolean[m][n];
ch = bt;
for(int k=0; k<m-1; k++){
for(int i=1; i<m; i++){
for(int j=0; j<n; j++){
if(boardd[i][j] == '0'){
boardd[i][j] = boardd[i-1][j];
boardd[i-1][j] = '0';
}
}
}
}
}
return answer;
}
}
'๐ป Coding Problems Solving > DFS | BFS | Backtracking' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ 1062] ๊ฐ๋ฅด์นจ (java) (0) | 2023.04.04 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๊ฒ์ ๋งต ์ต๋จ๊ฑฐ๋ฆฌ(java) (0) | 2023.03.31 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ํผ๋ก๋ (์๋ฐ java) (0) | 2023.03.01 |
[BOJ 1303] ์ ์-์ ํฌ (0) | 2022.07.04 |
[BOJ 1260] DFS์ BFS (0) | 2022.07.01 |
์ต๊ทผ๋๊ธ