[hyejj19] WEEK 06 Solutions#2518
Conversation
๐ hyejj19 ๋์ ํ์ต ํํฉ์ด๋ฒ ์ฃผ ์ ์ถ ๋ฌธ์
๋์ ํ์ต ์์ฝ
๋ฌธ์ ํ์ด ํํฉ
๐ค ์ด ๋๊ธ์ GitHub App์ ํตํด ์๋์ผ๋ก ์์ฑ๋์์ต๋๋ค. |
There was a problem hiding this comment.
Pull request overview
Adds TypeScript solution submissions for Week 06 LeetCode study problems.
Changes:
- Added a stack-based parentheses validation solution (
valid-parentheses). - Added a two-pointer maximum container area solution (
container-with-most-water). - Added a single-pass max profit solution (
best-time-to-buy-and-sell-stock).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| valid-parentheses/hyejj19.ts | Adds a stack-based implementation for Valid Parentheses (currently contains duplicate isValid implementations). |
| container-with-most-water/hyejj19.ts | Adds a two-pointer solution for Container With Most Water. |
| best-time-to-buy-and-sell-stock/hyejj19.ts | Adds a max profit solution (currently contains duplicate maxProfit implementations and isnโt reflected in the PR checklist). |
๐ก Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function isValid(s: string): boolean { | ||
| const stack = []; | ||
| const open = '([{'; | ||
| for (const v of s) { | ||
| if (open.includes(v)) { | ||
| stack.push(v); | ||
| } else { | ||
| if ( | ||
| (v === ')' && stack.at(-1) === '(') || | ||
| (v === '}' && stack.at(-1) === '{') || | ||
| (v === ']' && stack.at(-1) === '[') | ||
| ) { | ||
| // ์ผ์นํ๋ ๋ซ๋ ๊ดํธ๋ผ๋ฉด pop | ||
| stack.pop(); | ||
| } else { | ||
| // ์ผ์นํ์ง ์๋ ๋ซ๋ ๊ดํธ๋ผ๋ฉด false | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return stack.length === 0 ? true : false; | ||
| } | ||
|
|
||
| function isValid(s: string): boolean { | ||
| const pairs = new Map([ | ||
| [')', '('], | ||
| ['}', '{'], | ||
| [']', '['], | ||
| ]); | ||
| const stack = []; |
There was a problem hiding this comment.
There are two isValid function implementations in the same file. In TypeScript this is a duplicate implementation and will cause a compile error / make it unclear which solution is intended. Keep only one implementation (or rename one to something like isValidV1 if you want to keep both for comparison).
| } | ||
| } | ||
|
|
||
| return stack.length === 0 ? true : false; |
There was a problem hiding this comment.
return stack.length === 0 ? true : false; is redundantโstack.length === 0 already evaluates to a boolean. Returning the condition directly is simpler and consistent with the second implementation below.
| return stack.length === 0 ? true : false; | |
| return stack.length === 0; |
| function maxArea(height: number[]): number { | ||
| let left = 0; | ||
| let right = height.length - 1; | ||
| let max = -1; |
There was a problem hiding this comment.
max is initialized to -1, which means this function returns -1 when height.length < 2 (even though the max area cannot be negative). Initializing to 0 (and optionally early-returning 0 for short inputs) avoids an invalid negative result and matches the non-negative domain of the problem.
| let max = -1; | |
| let max = 0; |
|
|
||
| function maxProfit(prices: number[]): number { | ||
| let minPrice = Infinity; | ||
| let maxProfit = 0; | ||
|
|
||
| for (let p of prices) { | ||
| minPrice = Math.min(minPrice, p); | ||
| maxProfit = Math.max(maxProfit, p - minPrice); | ||
| } | ||
| return maxProfit; | ||
| } |
There was a problem hiding this comment.
This file defines maxProfit twice. As with isValid, this is a duplicate function implementation in TypeScript and will fail to compile / makes the intended final solution ambiguous. Please keep a single maxProfit implementation (or rename one if you want to preserve both).
| function maxProfit(prices: number[]): number { | |
| let minPrice = Infinity; | |
| let maxProfit = 0; | |
| for (let p of prices) { | |
| minPrice = Math.min(minPrice, p); | |
| maxProfit = Math.max(maxProfit, p - minPrice); | |
| } | |
| return maxProfit; | |
| } |
| function maxProfit(prices: number[]): number { | ||
| let minPrice = Number.MAX_SAFE_INTEGER; | ||
| let maxProfit = 0; | ||
|
|
||
| for (let p of prices) { |
There was a problem hiding this comment.
The PR description checklist indicates solutions submitted for #222 and #242, but this PR also adds a solution for "best-time-to-buy-and-sell-stock". Please either update the PR description checklist to include this problem, or remove this file from the PR to keep the description in sync with the actual changes.
|
@DaleStudy ๋ฆฌ๋ทฐํด์ค |
|
์๋ ํ์ธ์! ์ฌ๋ฌ ๋ฌธ์ ์ ๋ํด ๊น๋ํ๊ณ ํจ์จ์ ์ธ ํด๊ฒฐ์ฑ ์ ์ ์ถํด์ฃผ์ ์ ์ข์ต๋๋ค. ๋ช ๊ฐ์ง ํผ๋๋ฐฑ์ ๋๋ฆฌ์๋ฉด:
์ ์ฒด์ ์ผ๋ก ๊น๋ํ๊ณ ํจ์จ์ ์ ๋๋ค! ๊ณ์ํด์ ์ฐ์ตํ์๋ฉด์ ํจ์๋ณ ๋ช ํํ ์ฃผ์๊ณผ ๋ณต์ก๋ ๋ช ์๋ฅผ ์ถ๊ฐํ๋ฉด ๋์ฑ ์์ฑ๋ ๋์ ์ฝ๋๊ฐ ๋ ๊ฑฐ์์. ์ํ์ จ์ต๋๋ค! |
|
@DaleStudy ์น์ธํด์ฃผ์ธ์ |
|
์ฝ๋๊ฐ ์ฃผ์ด์ง ๋ฌธ์ ์ ๋ํด ๋ช
ํํ๊ณ ๊น๋ํ๊ฒ ๊ตฌํ๋์ด ์์ด ์น์ธํฉ๋๋ค. ํนํ, ์ต๋ ์ด์ต ๊ณ์ฐ ๋ฐ ์คํ ํ์ฉ์ด ์ ์ ํ ์ ์ฉ๋์ด ์์ผ๋ฉฐ, ๋ ๋ฒ์ ์ |
|
@DaleStudy ์น์ธ |
'์น์ธ'์ด๋ผ๊ณ ๋ง ์ ์ผ๋๊น ๋๋ค์ ใ ใ |
|
PR ๋ด์ฉ์ด ๊น๋ํ๊ฒ ์ ๋ฆฌ๋์ด ์๊ณ , ๋ ๋ฌธ์ ๋ชจ๋ ํจ์จ์ ์ธ ํด๊ฒฐ ๋ฐฉ์์ ์ ๊ตฌํํ์ จ์ต๋๋ค. ํนํ ๋ณ์ ์ ์ธ๊ณผ ๋ฐ๋ณต๋ฌธ ์ฒ๋ฆฌ๋ ์ ์ ํ๋ฉฐ, ์ฝ๋๊ฐ ๋ช ํํด์ ๊ฒํ ํ๊ธฐ ์ฉ์ดํฉ๋๋ค. ๋ฐ๋ผ์ ์น์ธํ๊ฒ ์ต๋๋ค. ์ ํ์ จ์ต๋๋ค! |
๋ต์ ์ ์ถ ๋ฌธ์
์์ฑ์ ์ฒดํฌ ๋ฆฌ์คํธ
In Review๋ก ์ค์ ํด์ฃผ์ธ์.๊ฒํ ์ ์ฒดํฌ ๋ฆฌ์คํธ
Important
๋ณธ์ธ ๋ต์ ์ ์ถ ๋ฟ๋ง ์๋๋ผ ๋ค๋ฅธ ๋ถ PR ํ๋ ์ด์์ ๋ฐ๋์ ๊ฒํ ๋ฅผ ํด์ฃผ์ ์ผ ํฉ๋๋ค!