Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[02주차 정지원] 타겟 넘버 #11

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**/*
!/**/*.py
!/**/*.java
!/**/*.js
!/**/*.c
!/**/*.cpp
!/**/*.yml
Expand Down
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
Comment on lines +2 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solution()numbers, targetdfs()안에서도 충분이 참조가 가능하니, 인자를 줄여보아도 괜찮을 것 같아요!

풀이는 전반적으로 아주 나이스하군요! 고생하셨습니다.

def solution(numbers, target):    
    def count_cases_by_dfs(index = 0, current = 0):
        if index == len(numbers):
            return 1 if current == target else 0
        return count_cases_by_dfs(index+1, current+numbers[index]) + count_cases_by_dfs(index+1, current-numbers[index])
    return count_cases_by_dfs()

10 changes: 10 additions & 0 deletions 03주차/정지원/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function solution(sizes) {
let maxW = 0;
let maxH = 0;
sizes.forEach((element) => {
element.sort((a, b) => a - b);
if (element[0] > maxW) maxW = element[0];
if (element[1] > maxH) maxH = element[1];
});
return maxW * maxH;
}
10 changes: 10 additions & 0 deletions 04주차/정지원/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def solution(triangle):
for i in range(1, len(triangle)):
for j in range(i + 1):
if j == 0:
triangle[i][j] += triangle[i - 1][j]
elif j == i:
triangle[i][j] += triangle[i - 1][j - 1]
else:
triangle[i][j] += max(triangle[i - 1][j], triangle[i - 1][j - 1])
return max(triangle[-1])
Loading