-
-
Notifications
You must be signed in to change notification settings - Fork 340
[hyejj19] WEEK 06 Solutions #2518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||||||||||||||||
| function maxProfit(prices: number[]): number { | ||||||||||||||||||||||||
| let minPrice = Number.MAX_SAFE_INTEGER; | ||||||||||||||||||||||||
| let maxProfit = 0; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| for (let p of prices) { | ||||||||||||||||||||||||
| if (minPrice >= p) { | ||||||||||||||||||||||||
| minPrice = p; | ||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| let profit = p - minPrice; | ||||||||||||||||||||||||
| if (profit > maxProfit) maxProfit = profit; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return maxProfit; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+16
to
+26
|
||||||||||||||||||||||||
| 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; | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||
| function maxArea(height: number[]): number { | ||||||
| let left = 0; | ||||||
| let right = height.length - 1; | ||||||
| let max = -1; | ||||||
|
||||||
| let max = -1; | |
| let max = 0; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||
| 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; | ||||||
|
||||||
| return stack.length === 0 ? true : false; | |
| return stack.length === 0; |
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.