-
-
Notifications
You must be signed in to change notification settings - Fork 246
[soobing] WEEK01 Solution #1675
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
base: main
Are you sure you want to change the base?
Conversation
const dp = (i: number) => { | ||
if (i < 0) return 0; | ||
if (memo.has(i)) return memo.get(i); | ||
|
||
const res = Math.max(dp(i - 1)!, dp(i - 2)! + nums[i]); | ||
memo.set(i, res); | ||
return res; | ||
}; |
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
함수의 반환 타입을 명시적으로 number로 지정해보는 건 어떨까요? const dp = (i: number): number => {
그렇게 하면 non-null assertion 없이도 컴파일러가 타입을 안전하게 추론해줘서 더 명확해질 것 같아요!!😊
if (this.heap.length === 0) return undefined; | ||
const min = this.heap[0]; | ||
const end = this.heap.pop(); | ||
if (this.heap.length > 0 && end !== undefined) { |
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.
if (this.heap.length === 0) return undefined;
로 힙에 값이 없으면 undefined를 반환하도록 되어 있으니 end !== undefined
는 없어도 되지 않을까요?
* 공간 복잡도: O(N) | ||
*/ | ||
class MinHeap { | ||
heap: [number, number][] = []; |
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.
[number, number][]
이 형식이 뭔지 궁금합니다!
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!