From ff2cc133165f6debd7f51cb35315022f46869cdd Mon Sep 17 00:00:00 2001 From: jiwonsudo Date: Sat, 21 Oct 2023 21:24:14 +0900 Subject: [PATCH] 2nd week upload --- .../\354\240\225\354\247\200\354\233\220/sol.py" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "02\354\243\274\354\260\250/\354\240\225\354\247\200\354\233\220/sol.py" diff --git "a/02\354\243\274\354\260\250/\354\240\225\354\247\200\354\233\220/sol.py" "b/02\354\243\274\354\260\250/\354\240\225\354\247\200\354\233\220/sol.py" new file mode 100644 index 0000000..9f471a5 --- /dev/null +++ "b/02\354\243\274\354\260\250/\354\240\225\354\247\200\354\233\220/sol.py" @@ -0,0 +1,13 @@ +def solution(numbers, target): + idx = 0 + current = 0 + + def dfs(list_of_nums, target_num, current_num, current_idx): + if current_idx == len(list_of_nums): + return 1 if current_num == target_num else 0 + + # 현재 상황에서 숫자를 빼거나 더하여 재귀함수 호출 + return dfs(list_of_nums, target_num, current_num + list_of_nums[current_idx], current_idx + 1) + dfs(list_of_nums, target_num, current_num - list_of_nums[current_idx], current_idx + 1) + + result = dfs(numbers, target, current, idx) + return result \ No newline at end of file