-
[Programmers] 타겟 넘버STUDYING/Algorithm 2021. 9. 27. 00:37728x90
https://programmers.co.kr/learn/courses/30/lessons/43165
import java.util.*; class Solution { static int answer; public int solution(int[] numbers, int target) { dfs(numbers, target, 0); return answer; } public static void dfs(int[] numbers, int target, int idx) { if (idx == numbers.length) { if (0 == target) answer++; return; } dfs(numbers, target - numbers[idx], idx + 1); dfs(numbers, target + numbers[idx], idx + 1); } }
'STUDYING > Algorithm' 카테고리의 다른 글
[Programmers] 실패율 (0) 2021.09.27 [Programmers] 가장 먼 노드 (0) 2021.09.27 [Programmers] 체육복 (0) 2021.09.27 [Programmers] 모의고사 (0) 2021.09.27 [Programmers] K번째 수 (0) 2021.09.27