Conversation
raejun92
approved these changes
Feb 13, 2026
Comment on lines
+5
to
+9
| const map = { | ||
| ")": "(", | ||
| "]": "[", | ||
| "}": "{", | ||
| }; |
doitchuu
approved these changes
Feb 14, 2026
Member
doitchuu
left a comment
There was a problem hiding this comment.
풀이가 깔끔하고 잘 푸셔서 많이 배워갑니다 👍
많이 자극받구가욤
| } else if (prices[i] - minPrice > currentProfit) { | ||
| currentProfit = prices[i] - minPrice; | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
else 문이 없다보니 아래처럼 풀어도 좋지 않을까 싶긴하네요 👍
기존 풀이도 깔끔해서 좋은 거 같아요!
for (let i = 0; i < prices.length; i++) {
if (prices[i] < minPrice) {
minPrice = prices[i];
continue;
}
const profit = prices[i] - minPrice;
if (profit > currentProfit) currentProfit = profit;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
이렇게 풀었어요
1. Two Sum
1) 복잡도 계산
시간 복잡도: O(n²)
공간 복잡도: O(1)
2) 접근 아이디어
배열의 모든 두 원소 조합을 직접 탐색하여 조건을 만족하는지 확인한다.
단계별 사고 과정
3) 회고
이 코드는 직관적이고 구현이 간단하다. 그러나 입력 크기가 커지면 비효율적인 코드가 된다. 특히 시간 복잡도는 1억 이상으로 넘어가면 시간 초과가 날 확률이 높다고 했는데, N이 10,000만 되어도 이 코드로는 해결이 불가능할 수 있다. 고로 이 문제는 Map을 이용해서 O(N)으로 최적화할 수 있다.
Map을 활용한 알고리즘 흐름
2. Valid Parentheses
1) 복잡도 계산
시간 복잡도: O(n)
공간 복잡도: O(n)
2) 접근 아이디어
가장 최근에 열린 괄호가 가장 먼저 닫혀야 한다. -> 전형적인 LIFO 구조 -> Stack
단계별 사고 과정
3) 회고
예전에 어디서 풀어봤던 문제라 바로 Stack을 사용했지만, 만약 이걸 모르는 상태였으면 (), {}, []를 replace 했을 것 같다. 근데 이건 최악의 경우 O(n²)의 시간 복잡도를 가지므로 좋은 방법은 아닌 것 같다.
3. Merge Two Sorted List
1) 복잡도 계산
시간 복잡도: O(N+M)
공간 복잡도: O(1)
2) 접근 아이디어
포인터를 옮기며 값을 탐색하는게 핵심이다. 따라서 각 리스트에 포인터를 옮겨가며 최솟값을 탐색해야한다.
단계별 사고 과정
3) 회고
사실 스스로 풀었다고는 못하겠다. 결국 해결책을 찾지 못해서 답을 보았다. 그리고, 재귀로도 해결할 수 있을 것 같은데 길이가 길면 스택오버플로우 발생 확률이 있어서 좋은 방법은 아닌것 같다.
재귀로 푸는 방법
4. Best Time To Buy And Sell Stock
1) 복잡도 계산
시간 복잡도: O(N)
공간 복잡도: O(1)
2) 접근 아이디어
오늘 판다고 가정했을 때, 과거 중 가장 싼 날에 샀다면 이익이 최대가 된다.
단계별 사고 과정
3) 회고