Skip to content

[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

Merged
merged 5 commits into from
May 3, 2025
Merged

[hsskey] Week 05 Solutions #1389

merged 5 commits into from
May 3, 2025

Conversation

hsskey
Copy link
Member

@hsskey hsskey commented Apr 28, 2025

답안 제출 문제

작성자 체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

let maxVal = 0

for(let i = 1; i < prices.length; i++) {
if(prices[i - 1] > prices[i]) {
Copy link
Contributor

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])을 비교하는 방식보다 더 간단하게 접근할 수 있을 것 같아요. 현재 가격이 지금까지의 최소값보다 크면 이익을 계산하고, 아니면 최소값을 갱신하는 방식으로요!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 로직도 성능적으로는 O(n) 시간 복잡도와 O(1) 공간 복잡도를 유지해서 효율적이네요 👍

Copy link
Member Author

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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

간결하고 효율적인 코드네요!
Map 객체 활용해서 애너그램 그룹핑한 방식이 깔끔하다고 생각합니다

정렬 방식으로 애너그램 판별하는 접근법도 문제 특성상 아주 적절한 선택이라고 생각합니다. 👍

Copy link
Member Author

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로 사용 → 같은 그룹으로 묶임

@hsskey hsskey moved this from Solving to In Review in 리트코드 스터디 4기 May 2, 2025
@hsskey hsskey merged commit 9e89a42 into DaleStudy:main May 3, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 4기 May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants