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.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!