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
20 changes: 20 additions & 0 deletions climbing-stairs/daehyun99.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와 유사한 누적 계산으로 풀이됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 최초 시도에서 이중 루프를 통해 조합을 누적 계산하므로 시간복잡도가 n에 대해 제곱으로 증가합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution:
def climbStairs(self, n: int) -> int:
one_count = n
two_count = 0
total_count = 0

while one_count >=0 and two_count >=0:
# 조합
total = one_count + two_count

count = 1
for i in range(two_count):
count *= total - i
for i in range(two_count, 0, -1):
count /= i
total_count += count

one_count -=2
two_count +=1
return int(total_count)
18 changes: 18 additions & 0 deletions product-of-array-except-self/daehyun99.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, Prefix / Suffix (Two Pointers), Hash Map / Hash Set
  • 설명: 배열 전체 곱에서 0 처리와 누적 곱을 이용해 각 위치의 곱을 구하는 방식으로, 특정 패턴으로 자주 언급되지만 정확히는 Prefix/Suffix 아이디어를 응용한 누적곱 패턴으로 볼 수 있습니다. 0의 위치를 세어 곱셈 결과를 결정하는 점에서 해를 구하는 그리디적 사고를 포함합니다.

📊 시간/공간 복잡도 분석

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

피드백: 0의 존재 여부에 따라 분기해 올바른 결과를 도출합니다. 한 번의 순회로 곱을 누적하고, 0의 개수에 따라 정답을 구성합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
product = 1
zero_pos = set()

for i in range(len(nums)):
num = nums[i]
if num != 0:
product *= num
else:
zero_pos.add(i)

if len(zero_pos) >= 2:
return [0 for num in nums]
elif len(zero_pos) == 1:
return [0 if i not in zero_pos else product for i in range(len(nums))]
else:
return [int(product / num) for num in nums]
16 changes: 16 additions & 0 deletions valid-anagram/daehyun99.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.

collections 의 Counter가 기본적으로 defaultdict(int) 처럼 없는 키값에 대해 0을 보낸다는것을 알고 계실까요?
그걸 쓰시면 훨씬 간단하게 작성하실수 있으실거에요!

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.

Counter는 해시 가능 객체를 세기 위한 dict 서브 클래스입니다.

@alphaorderly
오호 코테 풀면서 Counter을 자세히 알아본 적은 없었는데, dict의 한 종류였군요!
많이 유용할 것 같아요. 코멘트 감사합니다!

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, Two Pointers
  • 설명: 두 문자열의 각 문자 등장 횟수를 해시맵으로 카운트하고, 같은 길이 및 최종 카운트 0 여부를 확인하는 방식으로 두 단어의 아나그램 여부를 판단합니다. 부분적으로 두 포인터 순회(zip)와 해시 맵 카운트 패턴이 함께 사용됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 길이 일치 여부를 먼저 확인하고, 각 문자에 대해 증가/감소를 누적합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from collections import defaultdict
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
count = defaultdict(int)

if len(s) != len(t):
return False

for s_, t_ in zip(s, t):
count[s_] += 1
count[t_] -= 1

for key, val in count.items():
if val != 0:
return False
return True
Loading