[Chanz] WEEK 03 Solutions#2728
Conversation
Implement a method to check if a string is a palindrome, ignoring non-alphanumeric characters and case.
Implement Hamming weight calculation using bit manipulation.
Implement combination sum algorithm to find all unique combinations of candidates that sum to the target.
There was a problem hiding this comment.
๐ท๏ธ ์๊ณ ๋ฆฌ์ฆ ํจํด ๋ถ์
- ํจํด: Backtracking, Depth-First Search, Greedy
- ์ค๋ช : ์ฝ๋๋ ํน์ ์์๋ฅผ ํฌํจ/์ ์ธํ๋ฉฐ ๋ชจ๋ ์กฐํฉ์ ์ฌ๊ท์ ์ผ๋ก ํ์ํ๋ ๋ฐฑํธ๋ํน ๋ฐฉ์์ด๋ค. DFS๋ก ํธ๋ฆฌ๋ฅผ ์ํํ๋ฉฐ ํ๊น ํฉ์ ๋ง๋ ์กฐํฉ์ ์ฐพ๊ณ , ์์ ํฌํจ ์๋์ ์ ์ธ ์๋๋ฅผ ๋ฐ๋ณตํ๋ค.
๐ ์๊ฐ/๊ณต๊ฐ ๋ณต์ก๋ ๋ถ์
| ๋ณต์ก๋ | |
|---|---|
| Time | O(n * 2^n) |
| Space | O(n) |
ํผ๋๋ฐฑ: ๋ฐฑํธ๋ํน์ผ๋ก ๋ชจ๋ ๊ฐ๋ฅํ ์กฐํฉ์ ํ์ํ๋ ๋ฐฉ์์ด๋ฉฐ, ๊ฐ ์ฌ๊ท์์ ๋ถ๋ถํฉ(target)๊ณผ ๋จ์ ํ๋ณด๋ฅผ ์ถ์ ํ๋ค.
๊ฐ์ ์ ์: ํ์ฌ ๊ตฌํ์ด ์ ์ ํด ๋ณด์ ๋๋ค.
๐ก ํ์ด์ ์๊ฐ/๊ณต๊ฐ ๋ณต์ก๋๋ฅผ ์ฃผ์์ผ๋ก ๋จ๊ฒจ๋ณด์ธ์!
๐ Chanz82 ๋์ ํ์ต ํํฉ์ด๋ฒ ์ฃผ ์ ์ถ ๋ฌธ์
๋์ ํ์ต ์์ฝ
๋ฌธ์ ํ์ด ํํฉ
๐ค ์ด ๋๊ธ์ GitHub App์ ํตํด ์๋์ผ๋ก ์์ฑ๋์์ต๋๋ค. ๐ข API ์ฌ์ฉ๋ (gpt-5-nano)
|
There was a problem hiding this comment.
๐ท๏ธ ์๊ณ ๋ฆฌ์ฆ ํจํด ๋ถ์
- ํจํด: Bit Manipulation, Greedy
- ์ค๋ช : ์ ๋ ฅ ์ ์๋ฅผ ์ด์ง์๋ก ์ํํ๋ฉฐ ๊ฐ ๋นํธ๋ฅผ ๊ฒ์ฌํ๋ ๋ฐฉ์์ผ๋ก 1์ ๊ฐ์๋ฅผ ์ . ๋นํธ ์ง์ ์กฐ์์ ์๋์ง๋ง ์ด์ง ๋นํธ ํ์ ๊ด์ ์ ํจํด์ด๋ฉฐ, ๋จ์ ๋ฐ๋ณต์ผ๋ก ์ต๋๊ฐ ์ถ์ ์์ด ๋นํธ๋ฅผ ํ์ธํ๋ ์ ์์ Bit Manipulation์ ํด๋น.
๐ ์๊ฐ/๊ณต๊ฐ ๋ณต์ก๋ ๋ถ์
| ๋ณต์ก๋ | |
|---|---|
| Time | O(log n) |
| Space | O(1) |
ํผ๋๋ฐฑ: ๋นํธ๋ฅผ ์ฐจ๋ก๋ก ํ์ธํ๋ ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ์ผ๋ก ๊ฐ๋จํ๊ณ ์ง๊ด์ ์ด๋ค.
๊ฐ์ ์ ์: ํ์ฌ ๊ตฌํ์ด ์ ์ ํด ๋ณด์ ๋๋ค.
๐ก ํ์ด์ ์๊ฐ/๊ณต๊ฐ ๋ณต์ก๋๋ฅผ ์ฃผ์์ผ๋ก ๋จ๊ฒจ๋ณด์ธ์!
There was a problem hiding this comment.
๐ท๏ธ ์๊ณ ๋ฆฌ์ฆ ํจํด ๋ถ์
- ํจํด: Two Pointers, Hash Map / Hash Set
- ์ค๋ช : ๋ฌธ์์ด ์ ์ฒ๋ฆฌ ํ ์ ๋์์ ๋น๊ตํ๋ ํฌ ํฌ์ธํฐ ๋ฐฉ์์ผ๋ก ๋์นญ ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค. ์ค๊ฐ์ ์ผ์นํ์ง ์์ผ๋ฉด ์ฆ์ ๋ฐํํ๋ฉฐ, ๋จ์ ๋ถ๋ถ์ ํฌ์ธํฐ๋ฅผ ํ ์นธ์ฉ ์ขํ ์งํํฉ๋๋ค.
๐ ์๊ฐ/๊ณต๊ฐ ๋ณต์ก๋ ๋ถ์
| ๋ณต์ก๋ | |
|---|---|
| Time | O(n) |
| Space | O(n) |
ํผ๋๋ฐฑ: ์ ์ฒ๋ฆฌ๋ก ์ํ๋ฒณ/์ซ์๋ง ๋จ๊ฒจ ๋น๊ตํ๋ ์ ํ์ ์ธ ๋ฐฉ์์ด๋ค.
๊ฐ์ ์ ์: ํ์ฌ ๊ตฌํ์ด ์ ์ ํด ๋ณด์ ๋๋ค.
๐ก ํ์ด์ ์๊ฐ/๊ณต๊ฐ ๋ณต์ก๋๋ฅผ ์ฃผ์์ผ๋ก ๋จ๊ฒจ๋ณด์ธ์!
|
easy 2, medium 1 ๊ฐ ๋ฌธ์ ์ ๋ฒฝ์ ๊ณ์ ๋์ง ๋ชปํ๊ณ ์๋ค์..ใ ใ ๋ค์์ฃผ ๋ถ๋ฐํด๋ณด๊ฒ ์ต๋๋ค..ํ. |
xeulbn
left a comment
There was a problem hiding this comment.
์ ์ฒด์ ์ผ๋ก ์ฝ๋ ์ ์ฝ์ด๋ณด์์ต๋๋ค.
์ ๊ฐ ์ฃผ ์ธ์ด๊ฐ ์๋ฐ์ธ์ง๋ผ ์ค๋๋ง์ ํ์ด์ฌ ์ฝ๋๋ฅผ ์ฝ์ด๋ณด๋ ์ฆ๊ฑฐ์ ์ต๋๋ค.
์ด๋ฒ ์ฃผ๋ ๊ณ ์ํ์
จ์ต๋๋ค!
| @@ -0,0 +1,22 @@ | |||
| class Solution: | |||
| def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: | |||
|
|
|||
There was a problem hiding this comment.
combination์ ์ธ๋ถ ํจ์์ ์ง์ญ ๋ณ์๋ก ์ด๋ฏธ ์ ์ธ๋์ด ์์ด ๋ด๋ถ ํจ์์ ๋งค๊ฐ๋ณ์๋ก ๋ค์ ์ ๋ฌํ์ง ์์๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ด๋ถ ํจ์๊ฐ ํด๋ก์ ๋ก ์ง์ ์ฐธ์กฐํ๋๋ก ๋ณ๊ฒฝํ๋ฉด ํจ์ ์ธ์๋ฅผ ์ค์ด๊ณ ์ฝ๋์ ์๋๋ฅผ ์กฐ๊ธ ๋ ๋ช ํํ๊ฒ ํํํ ์ ์์ต๋๋ค.
๋ํ target์ ์ต์ด ๋ชฉํ๊ฐ์ด ์๋๋ผ ์ฌ๊ท ํธ์ถ๋ง๋ค ๋จ์ ๊ฐ์ ์๋ฏธํ๋ฏ๋ก remain๊ณผ ๊ฐ์ ์ด๋ฆ์ ์ฌ์ฉํ๋ฉด ๊ฐ๋ ์ฑ์ด ๋ ์ข์์ง ๊ฒ ๊ฐ์ต๋๋ค.
| alpha_num_str = "" | ||
| for ch in s: | ||
| if ch.isalnum(): | ||
| alpha_num_str += ch.lower() |
There was a problem hiding this comment.
Python์ ๋ฌธ์์ด์ ๋ถ๋ณ ๊ฐ์ฒด์ด๊ธฐ ๋๋ฌธ์ ๋ฐ๋ณต๋ฌธ ์์์ alpha_num_str += ch.lower()๋ฅผ ์ํํ๋ฉด ๋งค๋ฒ ์๋ก์ด ๋ฌธ์์ด์ด ์์ฑ๋๋ ๊ฒ์ผ๋ก ์๊ณ ์์ต๋๋ค. (์ ์ฃผ ์ธ์ด๊ฐ ์๋ฐ๋ผ ์ ํํ์ง ์์ต๋๋ค! ) ์ ๋ ฅ ํฌ๊ธฐ๊ฐ ์ปค์ง ๊ฒฝ์ฐ ๋ถํ์ํ ๋ฌธ์์ด ๋ณต์ฌ๊ฐ ๋ฐ์ํ ์ ์์ผ๋ฏ๋ก ๋ฆฌ์คํธ์ append()ํ ๋ค join()ํ๊ฑฐ๋, ํฌ ํฌ์ธํฐ๋ฅผ ์ด์ฉํด ์๋ณธ ๋ฌธ์์ด์์ ๋ฐ๋ก ๋น๊ตํ๋ ๋ฐฉ์์ด ๋ ์ ์ ํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค.
๋ต์ ์ ์ถ ๋ฌธ์
์์ฑ์ ์ฒดํฌ ๋ฆฌ์คํธ
In Review๋ก ์ค์ ํด์ฃผ์ธ์.๊ฒํ ์ ์ฒดํฌ ๋ฆฌ์คํธ
Important
๋ณธ์ธ ๋ต์ ์ ์ถ ๋ฟ๋ง ์๋๋ผ ๋ค๋ฅธ ๋ถ PR ํ๋ ์ด์์ ๋ฐ๋์ ๊ฒํ ๋ฅผ ํด์ฃผ์ ์ผ ํฉ๋๋ค!