일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 딕셔너리
- DP
- DFS
- 파이썬
- 스택
- 그래프 탐색
- 브루트포스 알고리즘
- JavaScript
- 문자열
- 구현
- lv2
- 프로그래머스
- CSS
- 자료구조
- BASIC
- 백준
- 알고리즘
- 그래프 이론
- programmers
- web
- 프로그래머스스쿨
- 그래프이론
- 정렬
- 너비 우선 탐색
- 다이나믹 프로그래밍
- 그리디 알고리즘
- 자바스크립트
- BFS
- level2
- 웹 프론트엔드
- Today
- Total
목록BASIC (4)
DevLog:-)

문제 코드 import sys from collections import deque N,M,V = map(int,sys.stdin.readline().strip().split()) graph =[[] for _ in range(N+1)] def dfs(cur_v): visited.append(cur_v) for v in graph[cur_v]: if(v not in visited): dfs(v) return visited def bfs(start_v): visited=[start_v] q = deque() q.append(start_v) while(q): cur_v =q.popleft() for v in graph[cur_v]: if(v not in visited): visited.append(v) q...

문제 Number of Islands - LeetCode Can you solve this real interview question? Number of Islands - Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent l leetcode.com 접근 방법 1.한 칸씩 확인한다.→ 이중for문 2.육지의 경우 주변을 다 탐색한다. → bfs or dfs 3.탐색한 육지는 다시 탐색하지 않도록 기록한다. →visite..
+visited 전역변수 사용코드 graph = { 'A':['B','D','E'], 'B':['A','C','D'], 'C':['B'], 'D':['A','B'], 'E':['A'] } visited =[] def dfs(cur_v): visited.append(cur_v) for v in graph[cur_v]: if v not in visited: dfs(v) dfs('A') print(visited) A를 시작으로 DFS탐색 경로 출력 +visited 지역변수 사용코드 graph = { 'A':['B','D','E'], 'B':['A','C','D'], 'C':['B'], 'D':['A','B'], 'E':['A'] } def dfs(graph,cur_v,visited=[]): visited.ap..
from collections import deque graph = { 'A':['B','D','E'], 'B':['A','C','D'], 'C':['B'], 'D':['A','B'], 'E':['A'] } def bfs(graph, start_v): visited=[start_v] #1.visit처리set queue = deque(start_v) #1.큐초기화set while(queue): cur_v = queue.popleft() #2.popleft for v in graph[cur_v]: #2.열결된 정점 확인 if(v not in visited): #3.조건 부합확인 visited.append(v) #3.visit처리 queue.append(v) #3.q처리 return visited print(..