프로그래머스/그래프
-
가장 먼 노드프로그래머스/그래프 2025. 3. 25. 14:47
import java.util.*;class Solution { // 각 노드까지의 거리 저장 배열 static int distance[]; // 가장 먼 노드의 거리 static int max; // 그래프를 인접 리스트 형태로 저장 static ArrayList> graph; static boolean visit[]; public int solution(int n, int[][] edge) { int answer = 0; max = Integer.MIN_VALUE; visit = new boolean[n+1]; distance = new int..
-
타겟 넘버 (DFS/BFS)프로그래머스/그래프 2022. 2. 4. 15:42
class Solution { static boolean check[]; static int N; static int count; public int solution(int[] numbers, int target) { N = numbers.length; check= new boolean[N]; count =0; dfs(0, numbers, target); return count; } public void dfs(int start, int[] numbers, int target) { int result=0; for(int i =0 ;i