[12주차] DAY1-dayeon - #242
Open
K-Dayeon03 wants to merge 29 commits into
Open
Conversation
Refactor solution method to use IntStream for summing divisors.
Week1/dayeon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
이슈 번호
#238
1.1 문제 이름
더 맵게
1.2 문제 정의
[input]
scoville: 각 음식의 스코빌 지수를 담은 정수 배열K: 목표 스코빌 지수모든 음식의 스코빌 지수를
K이상으로 만들기 위해 가장 맵지 않은 음식 2개를 선택해 새로운 음식을 만든다.새로운 음식의 스코빌 지수는 다음과 같이 계산한다.
가장 맵지 않은 음식 + (두 번째로 맵지 않은 음식 × 2)모든 음식의 스코빌 지수가
K이상이 될 때까지 반복하고, 섞은 횟수의 최솟값을 반환한다.만약 모든 음식의 스코빌 지수를
K이상으로 만들 수 없다면-1을 반환한다.1.3 알고리즘 설계
PriorityQueue를 사용한다.scoville배열의 모든 값을 최소 힙에 저장한다.K보다 작은 동안 다음 과정을 반복한다.first를 꺼낸다.second를 꺼낸다.first + second * 2로 새로운 스코빌 지수를 계산한다.K보다 작다면 더 이상 섞을 수 없으므로-1을 반환한다.K이상이라면 지금까지 섞은 횟수를 반환한다.1.4 시간 복잡도
N개의 값을 PriorityQueue에 삽입하는 과정에서 최대O(N log N)poll,add연산이 각각O(log N)N-1번의 혼합이 발생할 수 있으므로 전체 시간 복잡도는O(N log N)