Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 엘리스sw트랙
- Git
- 개발자취업
- HTML
- 99클럽
- 오픈소스기반데이터분석
- 파이썬
- aws
- Cookie
- CSS
- node.js
- 항해99
- 데이터베이스시스템
- 클라우드컴퓨팅
- 코딩테스트
- Python
- 프로그래머스
- TiL
- JavaScript
- nestjs
- 방송대컴퓨터과학과
- 파이썬프로그래밍기초
- 코딩테스트준비
- 중간이들
- 방송대
- 꿀단집
- 유노코딩
- 코드잇
- redis
- mongoDB
Archives
- Today
- Total
배꼽파지 않도록 잘 개발해요
99클럽 코테 스터디 31일차 TIL - Bad Grass 본문
function numIslands(grid) {
if (grid.length === 0) return 0;
const directions = [
[-1, 0], [1, 0], [0, -1], [0, 1],
[-1, -1], [-1, 1], [1, -1], [1, 1]
];
let count = 0;
function dfs(x, y) {
if (x < 0 || y < 0 || x >= grid.length || y >= grid[0].length || grid[x][y] === '0') {
return;
}
grid[x][y] = '0'; // Mark this cell as visited by setting it to '0'
for (let [dx, dy] of directions) {
dfs(x + dx, y + dy);
}
}
for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid[0].length; j++) {
if (grid[i][j] !== '0') {
count++;
dfs(i, j);
}
}
}
return count;
}
728x90
'코딩테스트 > 99클럽' 카테고리의 다른 글
99클럽 코테 스터디 31일차 TIL - 양 한마리 (0) | 2024.08.24 |
---|---|
99클럽 코테 스터디 31일차 TIL - Number of Good Leaf Nodes Pairs (0) | 2024.08.24 |
99클럽 코테 스터디 31일차 TIL - Clear Cold Water (0) | 2024.08.22 |
99클럽 코테 스터디 29일차 TIL - Arranging Coins (0) | 2024.08.21 |
99클럽 코테 스터디 29일차 TIL - Missing Number (0) | 2024.08.20 |