Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions container-with-most-water/ICE0208.py
Comment thread
parkhojeong marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def maxArea(self, height: List[int]) -> int:
left, right = 0, len(height) - 1

most_water_size = 0
while (left < right):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( ) 괄호는 붙이신 이유가 있을까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아뇨 없습니다🤣 다른 언어랑 왔다갔다하니 무의식적으로 괄호로 감싼 것 같네요 ㅎㅎ

left_h, right_h = height[left], height[right]

current_size = (right-left) * min(left_h, right_h)
most_water_size = max(most_water_size, current_size)

if left_h < right_h:
left += 1
else:
right -= 1


return most_water_size
47 changes: 47 additions & 0 deletions design-add-and-search-words-data-structure/ICE0208.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Trie, Depth-First Search, Backtracking
  • 설명: Trie를 활용한 단어 저장/검색 구조이며, '.' 와일드카드 처리 시 DFS로 모든 경로를 탐색한다. 백트래킹 성격의 재귀 호출로 모든 가능한 문자 조합을 확인하는 방식이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(L)
Space O(N)

피드백: 트라이로 단어를 저장하고 '.'를 재귀적으로 확장하는 표준 풀이이다.

개선 제안: 일반적으로 충분하지만, 메모리 사용량을 줄이려면 필요한 자식만 관리하는 구조를 고려해볼 수 있다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class TrieNode:
def __init__(self):
self.children = {}
self.is_end = False


class WordDictionary:

def __init__(self):
self.root = TrieNode()

def addWord(self, word: str) -> None:
current = self.root

for char in word:
if char not in current.children:
current.children[char] = TrieNode()

current = current.children[char]

current.is_end = True

def search(self, word: str) -> bool:
def dfs(index: int, node: TrieNode) -> bool:
# 패턴을 모두 확인했을 때 실제 단어의 끝인지 확인한다.
if index == len(word):
return node.is_end

char = word[index]

# '.'은 현재 노드의 모든 자식 문자와 대응될 수 있다.
if char == ".":
for child in node.children.values():
if dfs(index + 1, child):
return True

return False

# 일반 문자는 해당 자식 노드만 확인한다.
child = node.children.get(char)

if child is None:
return False

return dfs(index + 1, child)

return dfs(0, self.root)
12 changes: 12 additions & 0 deletions longest-increasing-subsequence/ICE0208.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N Log N 풀이법이 있습니다! 시도해 보시죠!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

알려주셔서 감사합니다! 예전에 O(n log n) 풀이와 증명까지 공부했었는데, 지금은 로직만 기억나고 왜 그렇게 동작하는지는 잘 떠오르지 않아 우선 정석적인 O(n²) 풀이로 제출했습니다.

말씀해 주신 O(n log n) 방식도 다시 찾아보며 공부해 보겠습니다. 감사합니다! ☺️

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming
  • 설명: 코드에서 dp 배열로 각 위치를 끝으로 하는 최장 증가 부분수열 길이를 계산하는 전형적인 동적계획법(DP) 패턴으로, 이중 루프를 이용해 상태 전이를 구성합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n^2)
Space O(n)

피드백: 단순 DP 방식으로 구현되어 있지만 시간 복잡도가 n^2으로 비효율적일 수 있다.

개선 제안: 가능하면 이분 탐색을 통한 O(n log n) 풀이로 변경하는 것을 고려해볼 만하다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
# dp[i] : i를 마지막으로 했을 때 가장긴 증가 부분수열
dp = [0] * len(nums)

for i in range(0, len(nums)):
dp[i] = 1
for j in range(0, i):
if nums[j] < nums[i]:
dp[i] = max(dp[i], dp[j] + 1)

return max(dp)
45 changes: 45 additions & 0 deletions spiral-matrix/ICE0208.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inRange 함수와 visit를 활용해서, matrix의 범위인지 체크하는 방법도 좋은 것 같네요!
다만, 공간 복잡도가 matrix만큼 추가로 필요하게 되네요.

문제에서 matrix의 shape을 알 수 있고, matrix를 순회하는 과정에서 shape 정보만으로 순회를 할 수 있습니다. 이를 활용하면, 추가적인 메모리 사용 없이 문제를 풀 수 있습니다. 시간이 되신다면, 이 방법으로 풀어보셔도 좋을 것 같아요!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b8faa50
일단 공간 복잡도를 줄이기 위해 별도의 visit 배열을 제거하는 방식으로 수정해 보았습니다!

다만 현재는 방문 여부를 표시하기 위해 matrix의 값을 직접 변경하고 있고, 말씀해 주신 방법과도 조금 다른 것 같아 나중에 다시 고민해 봐야겠네요 ㅎㅎ

혹시 top, right, bottom, left 경계값을 설정한 뒤, 순회하면서 각 경계를 줄여 나가는 방식을 말씀하신 게 맞을까요? 👀

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음 아래의 이미지처럼, matrixmn을 구할 수 있고, 단순히 첫 번째 이동은 m만큼, 두번째 이동은 n만큼, 세 번째 이동은 m-1만큼...하는 것을 말한 것이었습니다

image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 방식으로도 풀 수 있었네요!
감사합니다🙇‍♂️ 복습할 때 참고하겠습니다👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Monotonic Stack, Greedy
  • 설명: 해당 코드는 격자에서 한 방향으로 연속적으로 벽돌처럼 탐색하며, 방문 여부를 표시해 방향을 바꿔가며 나선 형태로 순회한다. 좌우상하로 방향을 전환하며 남은 미방문 칸을 따라가는 구조가 특징이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(mn)
Space O(1)

피드백: 방문 여부를 별도 상징값으로 관리하며 순회한다. 배치에 따라 약간의 비효율이 있을 수 있다.

개선 제안: 방문 표시 대신 경계 변수를 사용한 경계 기반 순회로 구현해도 된다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
VISIT_NUM = 10000

total = sum(map(lambda k: len(k), matrix))
answer = []

def isVisit(i, j):
return matrix[i][j] == VISIT_NUM

def setVisit(i, j):
matrix[i][j] = VISIT_NUM

def inRange(i, j):
if not (0<=i<len(matrix)):
return False
if not (0<=j<len(matrix[0])):
return False
return True

i, j = 0, 0
answer.append(matrix[0][0])
setVisit(0, 0)
while len(answer) < total:
while inRange(i, j+1) and not isVisit(i, j+1):

@parkhojeong parkhojeong Aug 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in range 와 is visit 을 하나로 묶어서 함수로 추상화 해도 좋을 거 같습니다

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러네요! 좋은 의견 감사드립니다!!

answer.append(matrix[i][j+1])
setVisit(i, j+1)
j += 1

while inRange(i+1, j) and not isVisit(i+1, j):
answer.append(matrix[i+1][j])
setVisit(i+1, j)
i += 1

while inRange(i, j-1) and not isVisit(i, j-1):
answer.append(matrix[i][j-1])
setVisit(i, j-1)
j -= 1

while inRange(i-1, j) and not isVisit(i-1, j):
answer.append(matrix[i-1][j])
setVisit(i-1, j)
i -= 1

return answer
37 changes: 37 additions & 0 deletions valid-parentheses/ICE0208.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Stack/Deque (implicitly), Hash Map / Hash Set
  • 설명: 스택(Deque)으로 여는 괄호를 push하고, 닫는 괄호를 만났을 때 일치하는지 확인하는 방식으로 유효성 검사를 수행한다. 매칭 맵으로 괄등 비교를 하고, 전체 문자열을 한 번 순회한다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 스택 기반으로 각 문자에 대응하는 매핑을 확인하는 전형적인 풀이이다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;

class Solution {
public boolean isValid(String s) {
Deque<Character> stack = new ArrayDeque<>();
Map<Character, Character> mapping = new HashMap<>();
mapping.put(')', '(');
mapping.put('}', '{');
mapping.put(']', '[');
Comment on lines +9 to +12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Map.of 사용해서 선언시점에 할당해도 좋을 거 같아요

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경되지 않는 고정된 값이니 Map.of()를 사용해도 되겠네요. 알려주셔서 감사합니다!


for (Character c : s.toCharArray()) {
// 열린 괄호일 때, 스택에 push
if (c=='(' || c=='{' || c == '[') {
stack.push(c);
continue;
}

// 닫힌 괄호일 때, 스택에서 pop한 뒤, 비교
// 스택이 비어있으면 탈락
if (stack.isEmpty()) {
return false;
}
Character popedC = stack.pop();
Character target = mapping.get(c);
// 같은 종류의 괄호가 아니면 탈락
if (!target.equals(popedC)) {
return false;
}
}

// 마지막에 스택이 비어있어야 성공
return stack.isEmpty();
}
}
Loading