Skip to content

Commit

Permalink
2nd week upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jiwonsudo committed Oct 21, 2023
1 parent 746a9f6 commit ff2cc13
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 02주차/정지원/sol.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ff2cc13

Please sign in to comment.