Skip to content

[alphaorderly] WEEK 03 Solutions#2707

Merged
alphaorderly merged 16 commits into
DaleStudy:mainfrom
alphaorderly:main
Jul 6, 2026
Merged

[alphaorderly] WEEK 03 Solutions#2707
alphaorderly merged 16 commits into
DaleStudy:mainfrom
alphaorderly:main

Conversation

@alphaorderly

Copy link
Copy Markdown
Contributor

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

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

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

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

Important

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

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

@dalestudy

dalestudy Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

๐Ÿ“Š alphaorderly ๋‹˜์˜ ํ•™์Šต ํ˜„ํ™ฉ

์ด๋ฒˆ ์ฃผ ์ œ์ถœ ๋ฌธ์ œ

๋ฌธ์ œ ๋‚œ์ด๋„ ์œ ํ˜• ๋ถ„์„
combination-sum Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
decode-ways Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
maximum-subarray Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
number-of-1-bits Easy โš ๏ธ ์œ ํ˜• ๋ถˆ์ผ์น˜
valid-palindrome Easy โœ… ์˜๋„ํ•œ ์œ ํ˜•

๋ˆ„์  ํ•™์Šต ์š”์•ฝ

  • ํ’€์ดํ•œ ๋ฌธ์ œ: 10 / 75๊ฐœ
  • ์ด๋ฒˆ ์ฃผ ์œ ํ˜• ์ผ์น˜์œจ: 80% (5๋ฌธ์ œ ์ค‘ 4๋ฌธ์ œ ์ผ์น˜)

๋ฌธ์ œ ํ’€์ด ํ˜„ํ™ฉ

์นดํ…Œ๊ณ ๋ฆฌ ์ง„ํ–‰๋„ ์™„๋ฃŒ
Array โ– โ– โ– โ–กโ–กโ–กโ–ก 4 / 10 (Medium 2, Easy 2)
Heap โ– โ– โ–กโ–กโ–กโ–กโ–ก 1 / 3 (Medium 1)
Dynamic Programming โ– โ–กโ–กโ–กโ–กโ–กโ–ก 2 / 11 (Easy 1, Medium 1)
Graph โ– โ–กโ–กโ–กโ–กโ–กโ–ก 1 / 8 (Medium 1)
String โ– โ–กโ–กโ–กโ–กโ–กโ–ก 1 / 10 (Easy 1)
Tree โ– โ–กโ–กโ–กโ–กโ–กโ–ก 1 / 14 (Medium 1)
Binary โ–กโ–กโ–กโ–กโ–กโ–กโ–ก 0 / 5 โ† ์•„์ง ์‹œ์ž‘ ์•ˆ ํ•จ
Interval โ–กโ–กโ–กโ–กโ–กโ–กโ–ก 0 / 5 โ† ์•„์ง ์‹œ์ž‘ ์•ˆ ํ•จ
Linked List โ–กโ–กโ–กโ–กโ–กโ–กโ–ก 0 / 6 โ† ์•„์ง ์‹œ์ž‘ ์•ˆ ํ•จ
Matrix โ–กโ–กโ–กโ–กโ–กโ–กโ–ก 0 / 4 โ† ์•„์ง ์‹œ์ž‘ ์•ˆ ํ•จ

๐Ÿค– ์ด ๋Œ“๊ธ€์€ GitHub App์„ ํ†ตํ•ด ์ž๋™์œผ๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ”ข API ์‚ฌ์šฉ๋Ÿ‰ (gpt-5-nano)
์š”์ฒญ ์ž…๋ ฅ ํ† ํฐ ์ถœ๋ ฅ ํ† ํฐ ํ•ฉ๊ณ„ ๋น„์šฉ
1 2,186 244 2,430 $0.000207
2 2,185 225 2,410 $0.000199
3 2,214 257 2,471 $0.000214
4 2,438 228 2,666 $0.000213
5 2,435 234 2,669 $0.000215
ํ•ฉ๊ณ„ 11,458 1,188 12,646 $0.001048

@Zero-1016 Zero-1016 self-requested a review July 5, 2026 01:51

@Zero-1016 Zero-1016 left a comment

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.

์•ˆ๋…•ํ•˜์„ธ์š” ๊ธˆ์ฃผ ๋ฆฌ๋ทฐ๋ฅผ ๋งก๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค ์ž˜ ๋ถ€ํƒ๋“œ๋ ค์š” :)

์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ์ „์ฒด์ ์œผ๋กœ ๋กœ์ง์ด ์ž˜ ์จ์ ธ์žˆ๊ณ  ์—ฌ๋Ÿฌ ๋ฐฉ๋ฉด์œผ๋กœ ํ’€์–ด๋ณด์‹  ๊ฒŒ ์ธ์ƒ์ ์ด์—ˆ์Šต๋‹ˆ๋‹ค.

์ €๋„ ์—ฌ๋Ÿฌ ๋ฐฉ๋ฉด์œผ๋กœ ํ’€์–ด๋ณด๋Š” ๊ฑธ ์—ฐ์Šตํ•ด ๋ด์•ผ๊ฒ ๋„ค์š”.

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.

๋‹ต ๋‘˜ ๋‹ค ์ •ํ™•ํ•œ ํ’€์ด๋„ค์š”. ๐Ÿ‘

ํ•œ ๊ฐ€์ง€ ๊ถ๊ธˆํ•œ ๊ฒŒ, ์‹ค์ œ ์ œ์ถœ์€ DP๋กœ ํ•˜๊ณ  ๋ฐฑํŠธ๋ž˜ํ‚น์„ ์ฃผ์„์œผ๋กœ ๋‚จ๊ธฐ์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?

์ด ๋ฌธ์ œ(๋ชจ๋“  ์กฐํ•ฉ ๋‚˜์—ด)๋Š” ์ถœ๋ ฅ ์ž์ฒด๊ฐ€ ์ง€์ˆ˜์ ์œผ๋กœ ์ปค์งˆ ์ˆ˜ ์žˆ์–ด์„œ, DP ์ชฝ์— ์ ํžŒ O(N*target) / O(target)์ด ์‹ค์ œ๋ณด๋‹ค ๋‚™๊ด€์ ์œผ๋กœ ๋ณด์—ฌ์š”.

dp[j].append(partial + [c]) ๋ถ€๋ถ„์ด ๋งค๋ฒˆ ๋ฆฌ์ŠคํŠธ๋ฅผ ํ†ต์งธ๋กœ ๋ณต์‚ฌํ•˜๊ณ , dp[0..target] ๊ฐ ์นธ์— ์ค‘๊ฐ„ ์กฐํ•ฉ๋“ค์„ ๋‹ค ๋“ค๊ณ  ์žˆ์–ด์„œ ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ชจ๋‘ ๊ทธ ํ‘œ๊ธฐ๋ณด๋‹จ ์ปค์งˆ ๊ฒƒ ๊ฐ™์•„์š”. ์˜คํžˆ๋ ค ์ฃผ์„ ์ฒ˜๋ฆฌ๋œ ๋ฐฑํŠธ๋ž˜ํ‚น์ด path ํ•˜๋‚˜๋ฅผ push/pop์œผ๋กœ ์žฌํ™œ์šฉํ•ด์„œ ๋ฉ”๋ชจ๋ฆฌ ๋ฉด์—์„  ๋” ์œ ๋ฆฌํ•ด ๋ณด์ด๋Š”๋ฐ, ํ˜น์‹œ DP๋ฅผ ๊ณ ๋ฅธ ํŠน๋ณ„ํ•œ ์ด์œ ๊ฐ€ ์žˆ์œผ๋ฉด ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

๋งž์•„์š”, ๋ฆฌ์ŠคํŠธ๋ฅผ ํ†ต์œผ๋กœ ๋ณต์‚ฌํ•˜๋Š” ๊ณผ์ •์—์„œ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์ƒ๊น๋‹ˆ๋‹ค!
๋‹ค๋งŒ ๋ฐฑํŠธ๋ž˜ํ‚น์€ target์˜ ๊ฐ’์ด ์ปค์ง€๋ฉด ์ปค์งˆ์ˆ˜๋ก exponentialํ•˜๊ฒŒ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ ์ปค์ง€๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์‹ค์ƒ ํฐ ๊ฐ’์—์„œ๋Š” ์‚ฌ์šฉํ•˜๊ธฐ ์–ด๋ ค์šธ๊ฒƒ์ด ์žˆ๊ณ , ๊ทธ์— ๋น„ํ•ด์„œ trade-off๋ฅผ ๊ณ ๋ คํ–ˆ์„๋•Œ DP๊ฐ€ ์ข€ ๋” ๋‚ซ๋‹ค๊ณ  ํŒ๋‹จํ–ˆ์–ด์š”!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

๋˜ํ•œ ๋ฐฑํŠธ๋ž˜ํ‚น๊ณผ ๋‹ฌ๋ฆฌ ์žฌ๊ท€๋ฅผ ์“ฐ์ง€ ์•Š์œผ๋‹ˆ ์žฌ๊ท€ ํ˜ธ์ถœ์— ์˜ํ•œ ์Šคํƒ ์˜ค๋ฒ„ํ—ค๋“œ๋„ ํ”ผํ• ์ˆ˜ ์žˆ๊ฒ ์ฃ 

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.

์žฌ๊ท€ ์Šคํƒ ํšŒํ”ผ๋Š” ๊ณ ๋ คํ• ๋งŒํ•œ ํŠธ๋ ˆ์ด๋“œ์˜คํ”„์ธ ๊ฒƒ ๊ฐ™๋„ค์š” ํŒŒ์ด์ฌ์€ ๊ธฐ๋ณธ ์žฌ๊ท€ ํ•œ๋„๊ฐ€ 1000์œผ๋กœ ์•Œ๊ณ ์žˆ์–ด target์ด ์•„์ฃผ ํฌ๋ฉด ๋ฐฑํŠธ๋ž˜ํ‚น์ด RecursionError๋ฅผ ๋‚ผ ์ˆ˜๋„ ์žˆ์œผ๋‹ˆ, ์ด๊ฑด DP๊ฐ€ ๋ถ„๋ช…ํžˆ ์ด๋“ ๋ณด๋Š” ์ง€์ ์œผ๋กœ ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค. ๐Ÿฅ‡

๋‹ค๋งŒ ๋‘ ๊ฐ€์ง€๋งŒ ๋ง๋ถ™์ด๋ฉด์š”. (1) ๋ฉ”๋ชจ๋ฆฌ๋Š” ์žฌ๊ท€ ์Šคํƒ O(depth)๋ณด๋‹ค DP๊ฐ€ ์ง€๋Š” ์ง(์ค‘๊ฐ„ ์กฐํ•ฉ ์ „๋ถ€ ์ €์žฅ + partial ๋ณต์‚ฌ)์ด ๋” ์ปค์„œ, ์ด๋Ÿ‰์€ ๋ฐฑํŠธ๋ž˜ํ‚น์ด ๊ฐ€๋ณ์Šต๋‹ˆ๋‹ค. (2) ์‹œ๊ฐ„์€ ๊ฒฐ๊ณผ ์กฐํ•ฉ ์ˆ˜๊ฐ€ ์ง€์ˆ˜์ ์ด๋ผ ๋‘˜ ๋‹ค ๊ฐ™์€ ์ง€์ˆ˜ ํ•˜ํ•œ์ด์—์š” โ€” ์ด ๋ถ€๋ถ„์—” DP๋„ ์ด๋“์ด ์—†์–ด์š”. ๊ทธ๋ž˜์„œ ๊ฐ•์ ์ด ์„œ๋กœ ๋‹ค๋ฅธ ์ชฝ(DP=์Šคํƒ ์•ˆ์ •, ๋ฐฑํŠธ๋ž˜ํ‚น=๋ฉ”๋ชจ๋ฆฌ/์ƒ์ˆ˜)์ด๋ผ๊ณ  ๋ณด๋Š” ๊ฒŒ ์ •ํ™•ํ•  ๊ฒƒ ๊ฐ™์•„์š”.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. ๊ทธ๊ฑด ํ™•์‹คํžˆ ๊ทธ๋ ‡๊ฒ ๋„ค์š”, ๋ฐฑํŠธ๋ž˜ํ‚น์€ ์ •๋‹ต์„ ๋ฐ”๋กœ๋ฐ”๋กœ ์Œ“์•„๋‚˜๊ฐ€๋‹ˆ ์‚ฌ์‹ค์ƒ ์“ธ๋ชจ์—†์ด ์“ฐ์ด๋Š” ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์ด ๊ฑฐ์˜ ์—†์„ํ…Œ๋‹ˆ๊นŒ์š”
  2. ๊ทธ๋ ‡๊ตฐ์š”

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.

๐Ÿ‘

Comment on lines +22 to +42
class Solution:
def isPalindrome(self, s: str) -> bool:
N = len(s)

left, right = 0, N - 1

while True:
while not s[left].isalnum() and left < right:
left += 1
while not s[right].isalnum() and left < right:
right -= 1

if left >= right:
break

if s[left].lower() == s[right].lower():
left, right = left + 1, right - 1
else:
return False

return 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.

๋ฐ”๊นฅ while True: + break ๊ตฌ์กฐ๊ฐ€ ๋™์ž‘์€ ์™„๋ฒฝํ•œ๋ฐ, ์กฐ๊ฑด์„ ์œ„๋กœ ์˜ฌ๋ฆฌ๋ฉด ํ๋ฆ„์ด ๋” ์ฝ๊ธฐ ์‰ฌ์›Œ์งˆ ๊ฒƒ ๊ฐ™์•„์š”.

class Solution:
    def isPalindrome(self, s: str) -> bool:
        left, right = 0, len(s) - 1
        while left < right:
            while left < right and not s[left].isalnum():
                left += 1
            while left < right and not s[right].isalnum():
                right -= 1
            if s[left].lower() != s[right].lower():
                return False
            left, right = left + 1, right - 1
        return True

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

๊ทธ๋ ‡๋„ค์š”, ์ฐจ๋ผ๋ฆฌ ์–ผ๋ฆฌ ๋ฆฌํ„ด์„ ํ•˜๋Š”๊ฒŒ ๋‚˜์•˜๊ธด ํ•˜๋„ค์š”

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Dynamic Programming, Backtracking
  • ์„ค๋ช…: ์ฃผ์„์— ์ฒ˜์Œ์€ ๋ฐฑํŠธ๋ž˜ํ‚น์œผ๋กœ ๋ชจ๋“  ์กฐํ•ฉ์„ ํƒ์ƒ‰ํ•˜๋Š” ์ „ํ˜•์  ํŒจํ„ด์ด ๋ณด์ด๊ณ , ๋‘ ๋ฒˆ์งธ ๊ตฌํ˜„์€ ๊ฐ ํƒ€๊ฒŸ ํ•ฉ์— ๋Œ€ํ•œ ๋ถ€๋ถ„ํ•ด๋ฅผ ์ €์žฅํ•˜๋Š” DP ๋ฐฉ์‹์œผ๋กœ ํ•ด๋ฅผ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ฐฑํŠธ๋ž˜ํ‚น๊ณผ ๋™์ ๊ณ„ํš๋ฒ• ๋‘ ํŒจํ„ด์ด ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(N * target)
Space O(target)

ํ”ผ๋“œ๋ฐฑ: ๊ฐ ํ›„๋ณด๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ๋ชฉํ‘œ ํ•ฉ๊นŒ์ง€์˜ ๋ชจ๋“  ๋ถ€๋ถ„ํ•ฉ์— ๋Œ€ํ•ด ๊ฐ€๋Šฅํ•œ ์กฐํ•ฉ์„ ํ™•์žฅํ•œ๋‹ค. dp ๋ฐฐ์—ด์˜ ๊ฐ ํ•ญ๋ชฉ์ด ๋ถ€๋ถ„ํ•ด๋ฅผ ๋‹ด๊ณ  ์žˆ์–ด ์‹œ๊ฐ„์€ ํ›„๋ณด ์ˆ˜์™€ ๋ชฉํ‘œํ•ฉ์— ๋น„๋ก€ํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Dynamic Programming, Two Pointers
  • ์„ค๋ช…: ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋Š” ๋ฌธ์ž์—ด s๋ฅผ ํ•œ ๋ฒˆ ์ˆœํšŒํ•˜๋ฉด์„œ ๋‘ ๋ฌธ์ž ๋‹จ์œ„๋กœ 26 ์ดํ•˜์˜ ์กฐํ•ฉ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜๊ณ , ์ด์ „ ์ƒํƒœ๋“ค์„ ํ•ฉ์‚ฐํ•ด ํ˜„์žฌ ์ƒํƒœ๋ฅผ ๊ฐฑ์‹ ํ•œ๋‹ค. ์ด๋Š” ๋ฌธ์ œ ํ•ด๊ฒฐ์„ ์œ„ํ•ด ์—ฐ์† ๋ถ€๋ถ„ํ•ด๋ฅผ ์ €์žฅํ•˜๋Š” DP ํŒจํ„ด์œผ๋กœ, Two Pointers์ฒ˜๋Ÿผ ์ธ๋ฑ์Šค ์ฐจ๋ฅผ ์œ ์ง€ํ•˜๋ฉฐ ๋ถ€๋ถ„ํ•ด๋ฅผ ๋ˆ„์  ๊ณ„์‚ฐํ•˜๋Š” ๋ฐฉ์‹์˜ ๋ณ€ํ˜•์ด๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(N)
Space O(1)

ํ”ผ๋“œ๋ฐฑ: ๋‘ ๋ณ€์ˆ˜๋งŒ์œผ๋กœ ์—ฐ์† ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๋ฉฐ ๊ฐ ์œ„์น˜์˜ ํ•ด์„ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค. ์‹œ์ž‘ ์กฐ๊ฑด๊ณผ 0 ์ฒ˜๋ฆฌ์— ์ฃผ์˜ํ•ด์•ผ ํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ•„์š”ํ•˜๋ฉด ๋ชจ๋“ˆ๋Ÿฌ ์—ฐ์‚ฐ์ด๋‚˜ ์ž…๋ ฅ ๊ฒ€์ฆ ๋กœ์ง์„ ์ถ”๊ฐ€ํ•ด ์•ˆ์ •์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Dynamic Programming, Greedy
  • ์„ค๋ช…: ํ•ด๋‹น ์ฝ”๋“œ๋Š” Kadane ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ์—ฐ์† ๋ถ€๋ถ„ ๋ฐฐ์—ด์˜ ์ตœ๋Œ“๊ฐ’์„ ๊ตฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ, ์ด์ „ ๊ตฌ๊ฐ„์˜ ์ตœ๋Œ“๊ฐ’์„ ํ˜„์žฌ ์›์†Œ์™€ ํ•ฉ์ณ ํ™•์žฅํ•˜๋Š” ์ ์—์„œ DP์˜ ์ตœ์  ๋ถ€๋ถ„๊ตฌ์กฐ์™€ Greedy์˜ ์„ ํƒ์„ฑ์„ ํ™œ์šฉํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(N)
Space O(1)

ํ”ผ๋“œ๋ฐฑ: ์ค‘์ฒฉ ๋ถ€๋ถ„๊ตฌ์กฐ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ์—ฐ์† ๋ถ€๋ถ„๋ฐฐ์—ด์˜ ์ตœ๋Œ“๊ฐ’์„ ์„ ํ˜• ์‹œ๊ฐ„์— ๊ตฌํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ์Œ์ˆ˜ ๋ฐฐ์—ด์— ๋Œ€ํ•ด์„œ๋„ ์•ˆ์ •์ ์œผ๋กœ ๋™์ž‘ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธ๋ฅผ ๋Š˜๋ฆฌ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Bit Manipulation
  • ์„ค๋ช…: ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋Š” ๋น„ํŠธ ์—ฐ์‚ฐ๊ณผ ๋น„ํŠธ ์‹œํ”„ํŠธ๋กœ 1์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ธ๋Š” ๋ฐฉ์‹์ด๋‹ค. n์˜ ์ตœํ•˜์œ„ ๋น„ํŠธ๋ฅผ ํ™•์ธํ•˜๊ณ (AND 1), ์ฐจ๋ก€๋กœ ์‹œํ”„ํŠธํ•˜์—ฌ ์ „์ฒด ์ž๋ฆฟ์ˆ˜๋ฅผ ๊ฒ€์‚ฌํ•œ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(์ˆซ์ž์˜ ๋น„ํŠธ ์ˆ˜)
Space O(1)

ํ”ผ๋“œ๋ฐฑ: ๋ฃจํ”„๊ฐ€ ๋น„ํŠธ๊ฐ€ 0์ด ๋  ๋•Œ๊นŒ์ง€ ์ˆ˜ํ–‰๋˜๋ฏ€๋กœ ์ž…๋ ฅ n์˜ ๋น„ํŠธ ๊ธธ์ด์— ๋น„๋ก€ํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: n & (n - 1) ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด 1๋น„ํŠธ๋ฅผ ์ œ๊ฑฐํ•˜๋ฉฐ ๋ฃจํ”„ ํšŸ์ˆ˜๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Two Pointers, Greedy, Hash Map / Hash Set
  • ์„ค๋ช…: ์ฃผ์š” ๋กœ์ง์€ ์ขŒ์šฐ ํฌ์ธํ„ฐ๋ฅผ ์ด์šฉํ•ด ๋ฌธ์ž์—ด์˜ ์–‘ ๋์—์„œ ๋ฌธ์ž ๋น„๊ต๋ฅผ ํ•˜๋ฉฐ ๋น„์•ŒํŒŒ์ˆซ๋ฌธ์ž ์ œ๊ฑฐ ๋ฐ ์†Œ๋ฌธ์ž ๋ณ€ํ™˜์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. ์ด์— ๋”ฐ๋ผ Two Pointers ํŒจํ„ด์ด ์ฃผ๋ฅผ ์ด๋ฃจ๊ณ , ๋ถˆํ•„์š” ์บ๋ฆญํ„ฐ ๊ฑด๋„ˆ๋›ฐ๊ธฐ ๋กœ์ง์€ Greedy ์„ฑ๊ฒฉ์˜ ๋‹จ์ˆœํ•œ ์ „์ง„์œผ๋กœ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(N)
Space O(1)

ํ”ผ๋“œ๋ฐฑ: ์ถ”๊ฐ€ ๋ฌธ์ž์—ด ์ƒ์„ฑ ์—†์ด ์ œ์ž๋ฆฌ์—์„œ ๊ฒ€์‚ฌํ•˜๋ฏ€๋กœ ๊ณต๊ฐ„ ์‚ฌ์šฉ์„ ์ค„์ธ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: isalpha/isnumeric ๊ฒ€์‚ฌ๋ฅผ ๋” ์—„๋ฐ€ํžˆ ํ•˜์—ฌ ์œ ํšจํ•œ ๋ฌธ์ž๋งŒ ๋น„๊ตํ•˜๋„๋ก ๊ฐ•ํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

@alphaorderly alphaorderly merged commit b2d8c3d into DaleStudy:main Jul 6, 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.

2 participants