-
Notifications
You must be signed in to change notification settings - Fork 126
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
[Flynn] week 3 #385
[Flynn] week 3 #385
Conversation
combination-sum/flynn.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 풀이 설명까지 감사합니다! ㅎㅎ 간결해서 보기 좋네요~!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다
|
||
} | ||
|
||
while (!q.empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이전 풀이도 그렇고, 큐와 스택을 정말 잘 쓰시네요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다
재귀보다는 반복문 사용하는 풀이를 좀 더 선호합니다 :D
중요한 부분은 아니지만, Combination Sum 문제의 좋은 풀이를 알기 쉽게 잘 써 주셨네요. 고생하셨습니다! |
중요하고 좋은 코멘트 감사합니다! |
제출 문제
체크 리스트
In Review
로 설정해주세요.설명
Two Sum
풀이
key: num, value: index
를 저장할 hashmap을 선언합니다.배열
nums
의 첫번째 원소를 hashmap에 저장합니다. (nums[0]: 0
)배열
nums
를 두번째 원소부터 조회하여target - nums[i]
가 hashmap에 존재하는지 판단합니다.만약
target - nums[i]
가 hashmap에 존재한다면 정답 배열을 반환하고, 그렇지 않다면 hashmap에 새로운 쌍을 추가합니다.Big-O
주어진 배열
nums
의 크기 N에 대해,Time complexity:
O(N)
nums
를 순회하기 때문에O(N)
의 시간 복잡도를 가집니다.Space complexity:
O(N)
nums
의 크기에 가깝게 커질 수 있으므로O(N)
의 공간복잡도를 가집니다.Climbing Stairs
풀이
다이나믹 프로그래밍을 이용하여 풀 수 있습니다.
아래와 같이
memo
배열을 정의했을 때,다음과 같은 점화식이 성립합니다.
Big-O
Time complexity: O(N)
Space complexity: O(N)
Product of Array Except Self
풀이
한 칸씩 밀린 상태로 누적곱을 배열에 기록해주는 것을 두 번 진행해주면 원하는 바를 얻을 수 있습니다.
Big-O
Time complexity: O(N)
Space complexity: O(N)
Coin Change
풀이
DP를 이용하여 풀이할 수 있습니다.
배열
memo
를 아래와 같이 정의합니다.앞서 정의한 배열
memo
를 이용하면 아래 점화식이 성립합니다.Big-O
배열
coins
의 크기를N
, 정수amount
의 크기를K
라고 했을 때,Time complexity:
O(N * M)
Space complexity:
O(M)
Combination Sum
풀이
queue
를 이용한 BFS로 주어진candidates
의 조합을 만듭니다.조합의 합 S의 크기에 따라 아래와 같이 연산을 진행합니다.
Big-O
candidates
배열의 크기를N
,target
의 크기를T
,candidates
배열의 원소 중 가장 작은 원소의 크기를K
라고 했을 때,Time complexity:
O(N ^ (T / K))
queue
에 담긴 각 조합은 다음 단계에서 �새 후보 숫자를 한 번씩 추가하여 최대 N개의 새로운 조합을 생성할 수 있습니다.Tree
에 빗대어 생각해보면 각node
당N
개의 자식들을 갖는다고 볼 수 있습니다Tree
의 깊이는T / K
에 비례합니다Space complexity:
O((T / K) * (N ^ (T / K)))
queue
의 크기는 앞서 말한Tree
의node
개수만큼 늘어날 수 있습니다node
가 지닌 조합 배열의 크기는T / K
까지 커질 수 있습니다