-
Notifications
You must be signed in to change notification settings - Fork 3
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
Ksg2388 : [19week] #116
Open
ksg2388
wants to merge
5
commits into
main
Choose a base branch
from
ksg2388/19week
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ksg2388 : [19week] #116
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# [68646] 풍선 터트리기 | ||
|
||
## :pushpin: **Algorithm** | ||
|
||
구현, 메모이제이션 | ||
|
||
## :round_pushpin: **Logic** | ||
|
||
```javascript | ||
for (let i = 1; i < a.length; i++) { | ||
leftMin[i] = Math.min(leftMin[i - 1], a[i]); | ||
rightMin[a.length - i - 1] = Math.min( | ||
rightMin[a.length - i], | ||
a[a.length - i] | ||
); | ||
} | ||
|
||
a.forEach((balloon, index) => { | ||
if (balloon <= leftMin[index] || balloon <= rightMin[index]) answer++; | ||
}); | ||
``` | ||
|
||
- 현재 인덱스에서 왼쪽에서의 가장 최소값과 오른쪽에서의 가장 최소값을 저장하는 배열을 만들어 저장해둔다. | ||
- 모든 배열을 돌면서 왼쪽과 오른쪽 중 하나라도 자신보다 큰 값이 있는 경우는 `answer`을 1증가 시킨다. | ||
|
||
## :black_nib: **Review** | ||
|
||
- 방법은 쉽게 떠올렸지만 메모이제이션을 사용하는 법이 바로 떠오르지 않아 시간초과가 났었다. | ||
- 간단한 코드 몇줄로 시간이 엄청나게 줄어든다는건 신기하다... |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function solution(a) { | ||
let answer = 0; | ||
let leftMin = Array.from({ length: a.length }, () => a[0]); | ||
let rightMin = Array.from({ length: a.length }, () => a[a.length - 1]); | ||
|
||
for (let i = 1; i < a.length; i++) { | ||
leftMin[i] = Math.min(leftMin[i - 1], a[i]); | ||
rightMin[a.length - i - 1] = Math.min( | ||
rightMin[a.length - i], | ||
a[a.length - i] | ||
); | ||
} | ||
a.forEach((balloon, index) => { | ||
if (balloon <= leftMin[index] || balloon <= rightMin[index]) answer++; | ||
}); | ||
return answer; | ||
} |
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.
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.
DP 공부 다시 하세요.