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/sonshn.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming
  • 설명: 피보나치 계열 점화식을 이용한 DP 접근으로, 각 단계의 해를 이전 두 단계의 합으로 구합니다. 문제의 최적해를 부분해의 합으로 구성하는 전형적인 DP 패턴.

📊 시간/공간 복잡도 분석

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

피드백: dp 배열을 사용해 각 단계의 경우의 수를 저장하며 i번째 값은 직전 값과 그 전 값을 더해 구합니다.

개선 제안: 메모리 사용을 줄이고 O(1) 공간으로 개선 가능(두 변수로만 상태를 유지하는 방법)

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* dp[i] = dp[i - 1] + dp[i - 2]
*/
class Solution {
public int climbStairs(int n) {
if (n <= 2) {
return n;
}

int[] dp = new int[n + 1];
dp[1] = 1;
dp[2] = 2;

for (int i = 3; i <= n; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}

return dp[n];
}
}
19 changes: 19 additions & 0 deletions valid-anagram/sonshn.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Sorting
  • 설명: 문자 배열을 정렬한 뒤 비교하는 방식으로 두 문자열의 구성 같음을 확인한다. 정렬이 주된 연산으로, 시간 복잡도는 O(n log n)이다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(nlogn) O(n log n)
Space O(n) O(n)

피드백: 두 문자열의 문자 배열을 정렬 후 비교하는 간단한 구현입니다.

개선 제안: ASCII 범위가 한정된 경우 카운팅 정렬처럼 선형 시간으로 개선 가능하고, 불필요한 정렬을 피하려면 문자 빈도수 비교로 구현해도 같습니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.*;

/**
* String to char array, sort, and compare
*
* 시간 복잡도: O(nlogn)
* 공간 복잡도: O(n)
*/
class Solution {
public boolean isAnagram(String s, String t) {
char[] sArray = s.toCharArray();
char[] tArray = t.toCharArray();

Arrays.sort(sArray);
Arrays.sort(tArray);

return Arrays.equals(sArray, tArray);
}
}
Loading