[devyejin] WEEK 05 solutions #1838
Conversation
printjin-gmailcom
left a comment
There was a problem hiding this comment.
์๊ณ ํ์ญ๋๋ค :)
| class Solution: | ||
| def maxProfit(self, prices: List[int]) -> int: | ||
| n = len(prices) | ||
| min_price = prices[0] |
There was a problem hiding this comment.
prices๊ฐ ๋น ๋ฐฐ์ด์ผ ๊ฒฝ์ฐ prices[0] ์ ๊ทผ์์ IndexError ๋ฐ์ ๊ฐ๋ฅ โ ์ ๋ ฅ ๊ฒ์ฆ ํ์
There was a problem hiding this comment.
๋ฌธ์ ์กฐ๊ฑด์์ prices ๊ธธ์ด๊ฐ 1์ด์์ด๋ผ๋ ๋ฌธ๊ตฌ๊ฐ ์์ด์ ์ ๋ฐ์์ผ๋ก ์ฒ๋ฆฌํ๊ธดํ๋๋ฐ, ๊ทธ๋๋ ์์ ํ๊ฒ ๊ฒ์ฆ ๋ก์ง ๋ฃ๋๊ฒ ์ข์๊น์?
There was a problem hiding this comment.
์ ์ ๊ฐ ์กฐ๊ฑด์ ๋ชป ๋ดค๋ค์. ์ด ๋ฌธ์ ์์๋ ํด๋น ์ฌํญ ๊ณ ๋ คํ์ง ์์ผ์ ๋ ๋ฉ๋๋ค.
|
|
||
| for word in wordDict: | ||
| if subs.startswith(word): | ||
| if dfs(subs[len(word):]): |
There was a problem hiding this comment.
๋ฉ๋ชจ์ด์ ์ด์ ์ ์ด์ฉํ ํ๋ค์ด DP๋ก ํ์ดํ์ ๊ฒ์ผ๋ก ๋ณด์ด๋ค์! ์ฝ๋๊ฐ ๋ช ํํ์ฌ ์ดํดํ๊ธฐ ์ฌ์ ์ต๋๋ค ใ ใ ใ
์ถ๊ฐ๋ก ์ด ๋ฌธ์ ์ DP ๋ฟ๋ง ์๋๋ผ #256 ๋ฌธ์ ์์ ๋ค๋ค๋ ํธ๋ผ์ด๋ ํจ๊ป ํ์ฉํ๋ค๋ฉด ๋งค ๋จ๊ณ๋ง๋ค wordDict ์ ์ฒด๋ฅผ ์ํํ๋ฉฐ subs.startswith(word)๋ฅผ ํ๋ ๋ถ๋ถ์ ์ต์ ํ ํ ์ ์์ต๋๋ค! ๋งจ ์ฒ์์ wordDict๋ฅผ ํธ๋ผ์ด์ ๋ฃ์ด๋๋ฉด ์ํํ ํ์ ์์ด ํธ๋ผ์ด๋ฅผ ๋ฐ๋ผ ๋ด๋ ค๊ฐ๋ฉฐ prefix๋ง ํ์ธํ ์ ์๊ธฐ ๋๋ฌธ์ธ๋ฐ์, ํ ๋ฒ ์ด๋ ๊ฒ๋ ํ์ด๋ณด์
๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค~!
There was a problem hiding this comment.
์์ธํ ํผ๋๋ฐฑ ๊ฐ์ฌ๋๋ฆฝ๋๋ค! ํ๋ฉด์๋ ๋นํจ์จ์ ์ธ ๋ถ๋ถ์ด ์๋ค ์ถ์๋๋ฐ ํธ๋ผ์ด๋ก ์ต์ ํํ ์ ์๋ค๋ ๊ฑด ์๊ฐ ๋ชปํ๋ค์. ์๋ ค์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค! ํธ๋ผ์ด๋ก ํ ๋ฒ ํ์ด๋ณด๊ฒ ์ต๋๋ค. ๐
๋ต์ ์ ์ถ ๋ฌธ์
์์ฑ์ ์ฒดํฌ ๋ฆฌ์คํธ
In Review๋ก ์ค์ ํด์ฃผ์ธ์.๊ฒํ ์ ์ฒดํฌ ๋ฆฌ์คํธ
Important
๋ณธ์ธ ๋ต์ ์ ์ถ ๋ฟ๋ง ์๋๋ผ ๋ค๋ฅธ ๋ถ PR ํ๋ ์ด์์ ๋ฐ๋์ ๊ฒํ ๋ฅผ ํด์ฃผ์ ์ผ ํฉ๋๋ค!