Skip to content

Conversation

minji-go
Copy link
Contributor

@minji-go minji-go commented Dec 26, 2024

답안 제출 문제

체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@minji-go minji-go requested a review from a team as a code owner December 26, 2024 15:36
@github-actions github-actions bot added the java label Dec 26, 2024
@minji-go minji-go requested a review from lylaminju December 26, 2024 15:37
public List<List<Integer>> answer = new ArrayList<>();

public List<List<Integer>> combinationSum(int[] candidates, int target) {
Arrays.sort(candidates);
Copy link
Contributor

Choose a reason for hiding this comment

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

불필요한 탐색을 줄이기 위해 정렬을 먼저하셨군요! 저는 생각못했는데, 성능 향상에 도움되는 것 같네요. 배워갑니다.

Copy link
Contributor

@lylaminju lylaminju left a comment

Choose a reason for hiding this comment

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

3주차 고생많으셨습니다. 따뜻하고 즐거운 연말 보내세요 :)

Time Complexity: O(Nⁿ), Runtime 2ms
Space Complexity: O(N), Memory 44.88MB

- Time Complexity, Space Complexity를 어떻게 계산해야할지 어렵네요 :(
Copy link
Contributor

Choose a reason for hiding this comment

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

저도 이 문제는 복잡도 계산이 어려운 것 같아요.

시간복잡도에 대해 조금 더 자세하게 써보자면,
재귀 호출의 깊이가 target에 비례하고, 각 깊이에서 N개의 후보 중 하나를 선택하기 때문에 $$O(N^T)$$ 라고 할 수도 있을 것 같습니다. (N은 후보 숫자의 개수, T는 target 값입니다.)

그리고 재귀 호출 스택의 깊이는 최대 target 값인 t에 비례하고, 현재까지 선택된 숫자들의 조합을 저장하는 공간도 최대 t개까지 저장하므로, 공간 복잡도는 $$O(t)$$ 라고 표현할 수 있을 것 같아요.

@minji-go minji-go merged commit 29a2b40 into DaleStudy:main Dec 28, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants