-
-
Notifications
You must be signed in to change notification settings - Fork 195
[moonjonghoo] Week 05 Solutions #1400
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
Conversation
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.
한 주 고생많으셨습니다 :) 저와 다르게 접근한 풀이들도 보면서 배우고 갑니다!
let maxProfit = 0; | ||
let currentProfit = 0; | ||
for (let i = 1; i < prices.length; i++) { | ||
let diff = prices[i] - prices[i - 1]; |
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.
맞습니다!
if (!hashMap.has(key)) { | ||
hashMap.set(key, [strs[i]]); | ||
} else { | ||
hashMap.set(key, [...hashMap.get(key), strs[i]]); |
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.
hashMap.get(key).push(strs[i]);
을 활용하면 새 배열을 생성하지 않고 바로 push 할 수 있습니다.
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.
아 맞습니다. 반영을 못했네요 ㅠㅠ
hashMap.set(key, [...hashMap.get(key), strs[i]]); | ||
} | ||
} | ||
let answer = []; |
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.
Array.from(hashMap.values())
를 활용할 수도 있습니다.
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.
오 그러네요 감사합니다.
const memo = new Map(); // 실패/성공 여부 기억 | ||
const wordSet = new Set(wordDict); // lookup 최적화 | ||
|
||
function canBreak(sub) { |
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.
재귀 + 메모이제이션 풀이 잘 보고 갑니다!
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!