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
13 changes: 13 additions & 0 deletions contains-duplicate/hellojoyworldz.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
  • 설명: 집합(set)을 이용해 중복 여부를 빠르게 확인하는 방식으로 해시 맵/해시 셋 패턴에 해당하며, 추가적인 탐색 없이 중복 여부를 한 번에 판단하는 간단한 해결책이다.

📊 시간/공간 복잡도 분석

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

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

피드백: 집합을 이용해 각 원소를 한 번씩 확인하면서 중복 여부를 확인한다.

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

풀이 2: containsDuplicate_alternative — Time: O(n log n) / Space: O(1)
복잡도
Time O(n log n)
Space O(1)

피드백: 정렬으로 중복 여부를 판단하므로 시간 복잡도가 증가한다.

개선 제안: 현재 구현이 더 효율적이므로 대안 필요 없음.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# - 문제: https://leetcode.com/problems/contains-duplicate/
# - 해설: https://www.algodale.com/problems/contains-duplicate/

# 217. Contains Duplicate
# - Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

from typing import List

class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:

return len(set(nums)) != len(nums)

18 changes: 18 additions & 0 deletions house-robber/hellojoyworldz.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Greedy
  • 설명: 이 코드는 인접한 집을 건너뛰며 최대 이익을 구하는 DP 점화식을 간단한 두 변수로 최적화한 방식이다. 각 위치의 최댓값을 이전 두 상태로 업데이트하는 슬라이딩 DP 패턴이 포함된다.

📊 시간/공간 복잡도 분석

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

피드백: 피보나치형 DP를 with two variables로 구현해 공간을 최소화했다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# - 문제: https://leetcode.com/problems/house-robber/
# - 풀이: https://www.algodale.com/problems/house-robber/

from typing import List


class Solution:
def rob(self, nums: List[int]) -> int:
prev1 = 0
prev2 = 0

for num in nums:
current = max(prev1, prev2 + num)
prev2 = prev1
prev1 = current

return prev1
Comment on lines +7 to +17

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.

dp 점화식을 변수로 두니까 공간복잡도가 많이 줄어드네요👍


26 changes: 26 additions & 0 deletions longest-consecutive-sequence/hellojoyworldz.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Sorting
  • 설명: 주어진 코드는 중복 제거 후 정렬으로 연속 증가 구간의 길이를 측정한다. 정렬과 연속 구간의 비교로 끝점까지의 길이를 누적하는 패턴이 핵심으로 보인다.

📊 시간/공간 복잡도 분석

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

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

피드백: 정렬이 주된 시간 복잡도이며, 중복 제거로 불필요한 비교를 줄인다.

개선 제안: 현재 구현이 명확하고 합리적이다.

풀이 2: longestConsecutive_optimized — Time: O(n) / Space: O(n)
복잡도
Time O(n)
Space O(n)

피드백: 해시셋을 이용하면 최악의 경우 O(n) 시간에 근접한 성능을 낼 수 있다.

개선 제안: 고려해볼 만한 개선 방향: 해시 기반 구현으로 시간 복잡도 개선 가능.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# - 문제: https://leetcode.com/problems/longest-consecutive-sequence/
# - 풀이: https://www.algodale.com/problems/longest-consecutive-sequence/

# Current complexity:O(NlogN)
# Suggested complexity:O(N)

from typing import List


class Solution:
def longestConsecutive(self, nums: List[int]) -> int:

sorted_nums = sorted(set(nums))

max_sequence = 1
current_sequence = 1

for i in range(1, len(sorted_nums)):
if sorted_nums[i] - sorted_nums[i - 1] == 1:
current_sequence += 1
max_sequence = max(max_sequence, current_sequence)
else:
current_sequence = 1

return max(max_sequence, current_sequence)

12 changes: 12 additions & 0 deletions top-k-frequent-elements/hellojoyworldz.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
  • 설명: Counter를 사용해 각 원소의 빈도수를 세고, 가장 많이 등장한 k개를 반환한다. 해시 맵 기반 빈도 계산과 빈도 높은 원소 선별로 구성된 간단한 패턴이다.

📊 시간/공간 복잡도 분석

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

피드백: 내장 자료구조를 활용해 구현이 간단하고 명확하다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# - 문제: https://leetcode.com/problems/top-k-frequent-elements/
# - 풀이: https://www.algodale.com/problems/top-k-frequent-elements/

from collections import Counter
from typing import List


class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
counter = Counter(nums)
return [num for num, count in counter.most_common(k)]

17 changes: 17 additions & 0 deletions two-sum/hellojoyworldz.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Brute Force, Two Pointers
  • 설명: 이 코드는 모든 쌍을 탐색하는 이중 루프로 두 원소의 합이 타깃이 되는지를 확인하는 전형적인 브루트 포스 패턴입니다. 다만 Two Pointers로 간주되려면 정렬 후 양 끝 포인터를 이동하는 방식이 필요합니다.

📊 시간/공간 복잡도 분석

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

피드백: 비효율적이므로 해시맵을 사용한 선형 시간 풀이가 일반적이다.

개선 제안: 고려해볼 만한 대안: 해시맵을 이용한 O(n) 풀이로 개선.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# - 문제: https://leetcode.com/problems/two-sum/
# - 해설: https://www.algodale.com/problems/two-sum/

from typing import List


class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for first_index, first_num in enumerate(nums):
for second_index, second_num in enumerate(nums):
if first_index == second_index:
continue
if first_num + second_num == target:
return [first_index, second_index]

return []
Comment on lines +7 to +16

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.

for문 중첩으로 시간복잡도가 높은데, 해시맵으로 개선하는 것도 좋을 것 같아요👍


Loading