Skip to content

Commit bff90c1

Browse files
committed
update project
1 parent acf93a9 commit bff90c1

7 files changed

Lines changed: 163 additions & 0 deletions

File tree

CodingTest/.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingTest/.idea/aws.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingTest/.idea/libraries/groovy_4_0_0_beta_1.xml

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingTest/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingTest/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodingTest/.idea/runConfigurations.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package graph_search.dfs;
2+
3+
public class IslandCountryIreland_1 {
4+
5+
public static void dfs(int x, int y, int[][] matrix){
6+
int[] dx = {-1, -1, 0, 1, 1, 1, 0, -1};
7+
int[] dy = {0, 1, 1, 1, 0, -1, -1, -1};
8+
matrix[x][y] = 0;
9+
for(int k = 0; k<8; k++){
10+
int nx = x + dx[k];
11+
int ny = y + dy[k];
12+
if(nx >= 0 && nx <matrix.length && ny >= 0 && ny < matrix.length && matrix[nx][ny] == 1){
13+
dfs(nx, ny, matrix);
14+
}
15+
}
16+
17+
18+
}
19+
20+
public static int solution(int sizeOfMatrix, int[][] matrix){
21+
int answer = 0;
22+
int n = sizeOfMatrix;
23+
24+
for(int i=0; i<n; i++){
25+
for(int j=0; j<n; j++){
26+
if(matrix[i][j] == 1){
27+
answer ++;
28+
dfs(i, j, matrix);
29+
}
30+
}
31+
}
32+
return answer;
33+
}
34+
35+
public static void main(String[] args){
36+
int[][] arr = {{1, 1, 0, 0, 0, 1, 0},
37+
{0, 1, 1, 0, 1, 1, 0},
38+
{0, 1, 0, 0, 0, 0, 0},
39+
{0, 0, 0, 1, 0, 1, 1},
40+
{1, 1, 0, 1, 1, 0, 0},
41+
{1, 0, 0, 0, 1, 0, 0},
42+
{1, 0, 1, 0, 1, 0, 0}};
43+
44+
System.out.println(solution(arr.length, arr));
45+
}
46+
}

0 commit comments

Comments
 (0)