-
-
Notifications
You must be signed in to change notification settings - Fork 247
[soobing] WEEK05 Solutions #1843
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
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.
한 주간 고생하셨습니다!
* | ||
*/ | ||
function maxProfit(prices: number[]): number { | ||
let min = prices[0]; |
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.
minPrice 처럼 의미가 분명한 변수명을 사용하면 좋을 것 같습니다.
|
||
for (let i = 0; i < strs.length; i++) { | ||
const key = strs[i].split("").sort().join(""); | ||
map.set(key, [...(map.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.
map.set()은 매번 새 배열을 만들어야하니 꺼내서 push 하는 방식은 어떤가요?
const length = Number(tempStr.slice(0, i)); | ||
const currentStr = tempStr.slice(i + 1, i + 1 + length); | ||
result.push(currentStr); | ||
tempStr = tempStr.slice(length + 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.
slice로 원본을 잘라내면 불필요한 문자열 복사가 반복될 수 있으니 포인터를 만들어서 전진하는 방식도 고려해보면 좋을 것 같아요
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!