Skip to content

[doh6077] WEEK 01 solutions#2370

Merged
SamTheKorean merged 6 commits intoDaleStudy:mainfrom
doh6077:main
Mar 8, 2026
Merged

[doh6077] WEEK 01 solutions#2370
SamTheKorean merged 6 commits intoDaleStudy:mainfrom
doh6077:main

Conversation

@doh6077
Copy link
Copy Markdown
Contributor

@doh6077 doh6077 commented Mar 3, 2026

๋‹ต์•ˆ ์ œ์ถœ ๋ฌธ์ œ

์ž‘์„ฑ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

  • Projects์˜ ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ(โ–ผ)์„ ๋ˆŒ๋Ÿฌ ํ™•์žฅํ•œ ๋’ค, Week๋ฅผ ํ˜„์žฌ ์ฃผ์ฐจ๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ๋ฌธ์ œ๋ฅผ ๋ชจ๋‘ ํ‘ธ์‹œ๋ฉด ํ”„๋กœ์ ํŠธ์—์„œ Status๋ฅผ In Review๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ์ฝ”๋“œ ๊ฒ€ํ† ์ž 1๋ถ„ ์ด์ƒ์œผ๋กœ๋ถ€ํ„ฐ ์Šน์ธ์„ ๋ฐ›์œผ์…จ๋‹ค๋ฉด PR์„ ๋ณ‘ํ•ฉํ•ด์ฃผ์„ธ์š”.

๊ฒ€ํ† ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

Important

๋ณธ์ธ ๋‹ต์•ˆ ์ œ์ถœ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค๋ฅธ ๋ถ„ PR ํ•˜๋‚˜ ์ด์ƒ์„ ๋ฐ˜๋“œ์‹œ ๊ฒ€ํ† ๋ฅผ ํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค!

  • ๋ฐ”๋กœ ์ด์ „์— ์˜ฌ๋ผ์˜จ PR์— ๋ณธ์ธ์„ ์ฝ”๋“œ ๋ฆฌ๋ทฐ์–ด๋กœ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.
  • ๋ณธ์ธ์ด ๊ฒ€ํ† ํ•ด์•ผํ•˜๋Š” PR์˜ ๋‹ต์•ˆ ์ฝ”๋“œ์— ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ์„ธ์š”.
  • ํ† ์š”์ผ ์ „๊นŒ์ง€ PR์„ ๋ณ‘ํ•ฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์Šน์ธํ•ด์ฃผ์„ธ์š”.

@ykim7 ykim7 self-requested a review March 4, 2026 01:30
Copy link
Copy Markdown
Contributor

@ykim7 ykim7 left a comment

Choose a reason for hiding this comment

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

set์„ ์ด์šฉํ•˜์—ฌ ์ค‘๋ณต๋œ ๊ฐ์ฒด๊ฐ€ ์žˆ์–ด์„œ ๊ธธ์ด๊ฐ€ ์ค„์–ด๋“  ๊ฒฝ์šฐ, ๊ทธ๊ฒƒ์„ ๋น„๊ตํ•˜์—ฌ ์ค‘๋ณต์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•œ ๊ฒƒ์ด ์ข‹์•˜์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๊ฐ€ ์งง๊ณ  ์ฝ๊ธฐ ์‰ฝ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
์ง€๊ธˆ๋„ ์ถฉ๋ถ„ํ•˜์ง€๋งŒ, ์ค‘๊ฐ„์— ์ค‘๋ณต์„ ๋ฐœ๊ฒฌํ•˜๋ฉด ์กฐ๊ธฐ ์ข…๋ฃŒํ•˜๋Š” ๋ฐฉ์‹๋„ ๊ณ ๋ คํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

@ykim7 ykim7 left a comment

Choose a reason for hiding this comment

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

ํ•ด์‹œ๋งต์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์— ๋น„ํ•ด ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ O(n)์œผ๋กœ ์ค„์—ฌ์„œ ํšจ์œจ์ ์œผ๋กœ ํ’€์ดํ–ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

# use Hash map to save num and index
nums_hm = {}

for i, num in enumerate(nums):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

enumerate๋ฅผ ์‚ฌ์šฉํ•ด์„œ index์™€ num์„ ๋™์‹œ์— ๊ฐ€์ ธ์˜จ ์ ์ด ์ข‹์•˜์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

@ykim7 ykim7 left a comment

Choose a reason for hiding this comment

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

๋‹จ๊ณ„๋ณ„๋กœ ์ฝ๊ธฐ ์‰ฝ๊ณ  ์ดํ•ด๊ฐ€ ์ž˜ ๋˜๋Š” ์ฝ”๋“œ์˜€์Šต๋‹ˆ๋‹ค.
๋‹ค๋งŒ freq๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ณผ์ •์€ O(n)์ด์ง€๋งŒ, ์ดํ›„ sorted()๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ ์ •๋ ฌ์— O(m log m)์ด ์ถ”๊ฐ€๋กœ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋นˆ๋„๋ฅผ ์ธ๋ฑ์Šค๋กœ ์‚ฌ์šฉํ•˜๋Š” bucket ๊ตฌ์กฐ๋ฅผ ํ™œ์šฉํ•˜๋ฉด O(n)์— ๊ฐ€๊น๊ฒŒ ํ’€ ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋นˆ๋„: ์ˆซ์ž ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ๋กœ ์ €์žฅํ•œ ๋’ค, ๋†’์€ ๋นˆ๋„๋ถ€ํ„ฐ ํƒ์ƒ‰ํ•˜๋Š” ๋ฐฉ์‹๋„ ํ•˜๋‚˜์˜ ๋Œ€์•ˆ์ด ๋  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

freq[num] += 1

# 2. Sort by frequency in descending order
sorted_items = sorted(freq.items(), key=lambda item: item[1], reverse=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sorted๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ reverse ์˜ต์…˜ ์™ธ์— key ์˜ต์…˜์„ ๋„ฃ์–ด ๊ฐ’์„ ๋น„๊ตํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์„ ์•Œ์•˜์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

@ykim7 ykim7 left a comment

Choose a reason for hiding this comment

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

์ „๋ฐ˜์ ์œผ๋กœ ํ๋ฆ„์ด ์ž˜ ๋ณด์ด๊ณ  ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ํ’€์ด์˜€์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ ์ด ๋ฌธ์ œ์—์„œ๋Š” ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ์–˜๊ธฐํ•˜๊ณ  ์žˆ์–ด ๊ทธ ๊ด€์ ์—์„œ ๋‹ค์‹œ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ ์ฝ”๋“œ๋Š” sort()๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ O(n log n)์˜ ์‹œ๊ฐ„ ๋ณต์žก๋„๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ , ์ดํ›„ while loop๋Š” O(n)์ด๋ฏ€๋กœ ์ „์ฒด์ ์œผ๋กœ O(n log n)์ด ๋˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์ •๋ ฌ ๋Œ€์‹  ์ด์ „ ๋ฌธ์ œ์—์„œ ์‚ฌ์šฉํ•˜์…จ๋˜ set์„ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์ƒ๊ฐํ•ด ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. set์€ ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜๊ณ , ์žˆ๋Š”์ง€ ์—†๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๋Š” ํƒ์ƒ‰์ด O(1)์ด๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ์ด์šฉํ•˜๋ฉด ์ „์ฒด ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ O(n)์— ๊ฐ€๊น๊ฒŒ ์ค„์ผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@SamTheKorean SamTheKorean merged commit 6f915fd into DaleStudy:main Mar 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants