-
-
Notifications
You must be signed in to change notification settings - Fork 195
[hsskey] Week 05 Solutions #1389
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
let maxVal = 0 | ||
|
||
for(let i = 1; i < prices.length; i++) { | ||
if(prices[i - 1] > prices[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.
인접한 가격(prices[i-1], prices[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.
지금 로직도 성능적으로는 O(n) 시간 복잡도와 O(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.
직관적으로 생각해서 풀이했던 내용인데 피드백 주신내용으로 다시 풀어봐야겠네요 감사합니다.
} | ||
} | ||
|
||
return Array.from(map.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.
간결하고 효율적인 코드네요!
Map 객체 활용해서 애너그램 그룹핑한 방식이 깔끔하다고 생각합니다
정렬 방식으로 애너그램 판별하는 접근법도 문제 특성상 아주 적절한 선택이라고 생각합니다. 👍
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.
알파벳 빈도수 배열로 그룹화하는 방식으로도 풀 수 있는 방법을 알게 되서 공유드려요
"eat" → [1, 0, 0, ..., 1, ..., 1] → a:1, e:1, t:1
"tea" → 같은 구성 → 같은 배열
이 배열을 string으로 바꿔서 Map의 key로 사용 → 같은 그룹으로 묶임
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!