Skip to content
Open
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
13 changes: 13 additions & 0 deletions best-time-to-buy-and-sell-stock/dolphinflow86.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.

깔끔하게 잘 해결해 주셨네요!
best time to buy and sell stock, 즉 해당 문제는
뒤에 로마 숫자를 붙혀서 1, 2, 3, 4, 5 총 다섯종류가 있는데요
dp 연습하기에 정말 괜찮은 문제라고 생각해서
2번문제
II는 한번 풀어보시길 추천드려요!

Copy link
Copy Markdown
Contributor 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy, Two Pointers
  • 설명: 가격을 순회하며 현재 값과 이전 최저가의 차이를 최대 이익으로 업데이트하는 방식으로, 한 번의 패스에서 최적 해를 찾는 그리디 패턴에 해당합니다. 또한 좌우로 한 방향으로만 값을 비교하므로 투 포인터의 아이디어가 적용됩니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N) O(n)
Space O(1) O(1)

피드백: 최소값과 최대 이익을 변수로 유지하며 배열을 한 번만 지나므로 시간 복잡도는 선형이고 추가 공간은 상수이다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 1) Keep track of local minimum and use local minimum to update max profile while interating prices.
# TC: O(N) where N is the length of prices
# SC: O(1)
class Solution:
def maxProfit(self, prices: List[int]) -> int:
min_price = prices[0]
max_profit = 0

for price in prices:
max_profit = max(max_profit, price - min_price)
min_price = min(min_price, price)
Comment on lines +9 to +11

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.

사소하지만 더 최적화 할 수 있는 부분은 min, max 일 거 같아요. 고민해보셔도 좋을 거 같습니다!


return max_profit
30 changes: 30 additions & 0 deletions encode-and-decode-strings/dolphinflow86.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy, Two Pointers, Hash Map / Hash Set, Divide and Conquer, Dynamic Programming, Binary Search, Monotonic Stack, Trie, Backtracking, DFS, BFS, Union Find, Heap / Priority Queue, Bit Manipulation, Sliding Window
  • 설명: 문자열 인코딩/디코딩에서 길이와 구분자를 이용해 각 단어를 구분하는 방식으로 문자열을 재구성한다. 포맷화된 순회와 인덱스 관리로 부분 문자열을 찾아내는 과정이 핵심이며, 이 로직은 문자열 처리의 탐색형 접근으로 해석된다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: Solution.encode — Time: O(n) / Space: O(1)
복잡도
Time O(n)
Space O(1)

피드백: 정확히 각 문자열의 길이를 앞에 기록하므로 구분자 없이도 경계 구분이 가능하다.

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

풀이 2: Solution.decode — Time: O(n) / Space: O(k)
복잡도
Time O(n)
Space O(k)

피드백: 루프를 통해 순차적으로 디코딩하므로 시간 복잡도는 선형이고 결과를 저장하는 공간이 필요하다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 1) Prepend each word with its length and a delimiter '%'.
# TC: encode O(N) where N is the len(str), decode O(N) where N is the len(s)
# SC: O(N) for storing the encoded string
class Solution:

def encode(self, strs: list[str]) -> str:
answer = ""
for s in strs:
answer += f"{len(s)}%{s}"
return answer

def decode(self, s: str) -> list[str]:
left = 0
right = 0
str_len = len(s)

result = []
while right < str_len:
while s[right] != "%":
right += 1

num_len = int(s[left:right])
start = right + 1
word = s[start : start + num_len]
result.append(word)

left = start + num_len
right = left

return result
13 changes: 13 additions & 0 deletions group-anagrams/dolphinflow86.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy
  • 설명: 문자열들을 정렬된 형태로 키로 삼아 그룹화하는 아이디어로 해시 맵에 묶는 패턴이며, 각 단어를 정렬해 같은 키를 갖는 경우를 모아 집합처럼 묶는 방식이다. 따라서 해시 맵을 활용하는 패턴이 핵심이다.

📊 시간/공간 복잡도 분석

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

피드백: 문자열 정렬이 주된 비용이며, 그룹화를 위한 해시맵 사용으로 효율적으로 묶을 수 있다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 1) Group words by their sorted form using defaultdict. While iterating the strs, sort each word and append original word to the corresponding list. After then convert dict to 2 dimensional list and return the list.
# TC: O(N*LlogL) where N is length of strs, L is max length of a word.
# SC: O(N*L)

class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
groups = defaultdict(list)

for str in strs:
sorted_str = "".join(sorted(str))
groups[sorted_str].append(str)

return list(groups.values())
Loading