728x90
https://school.programmers.co.kr/learn/courses/30/lessons/43165
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
using System;
public class Solution {
private int answer =0 ;
public int solution(int[] numbers, int target) {
DFS(0, -1, numbers, target);
return answer;
}
private void DFS(int sum, int index, int[] numbers, int target){
if (index >= numbers.Length-1){
if (sum == target) answer++;
return;
}
index++;
DFS(sum + numbers[index], index, numbers, target);
DFS(sum - numbers[index], index, numbers, target);
}
}
728x90
'공부 > C#' 카테고리의 다른 글
[C#] 프로그래머스 - DFS 연습 네트워크 (0) | 2025.03.01 |
---|---|
[C#] 재귀방식, list를 활용한 DFS 기본 형태 (0) | 2025.02.28 |
꿀꺽 (0) | 2023.08.09 |
냠냠 (0) | 2023.08.07 |
[프로그래머스] C# 2023 KAKAO BLIND RECRUITMENT 이모티콘 할인행사 Lv 2 / DFS (0) | 2023.08.05 |