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
24 changes: 24 additions & 0 deletions climbing-stairs/hoonjichoi1.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, Fibonacci Sequence (implicit), Greedy
  • 설명: 문제는 계단 오르기 값을 피보나치처럼 점화식으로 계산하며, 반복문으로 이전 값 두 개를 저장해 현재 값을 구하는 DP 기반 구현이다. 최적해를 상향식으로 구성하는 전형적인 Dynamic Programming 패턴이다.

📊 시간/공간 복잡도 분석

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

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

피드백: 상수 공간으로 이전 두 항만 저장하고 순차적으로 업데이트하여 시간 복잡도는 선형으로 구해진다.

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

풀이 2: hoonjichoi1.isAnagram — Time: O(n + m) / Space: O(k)
복잡도
Time O(n + m)
Space O(k)

피드백: 두 문자열의 길이가 n, m일 때 해시맵에 최대 서로 다른 문자 수만큼 공간이 필요하고, 모든 문자의 빈도 차이를 확인한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

/*
f(45) = f(44) + f(43)
f(44) = f(43) + f(42)
.
.
.
f(3) = f(2) + f(1)
f(2) = 2
f(1) = 1
*/
class Solution {
public int climbStairs(int n) {
if (n <= 2) return n;

int prev = 1, cur = 2;
for (int i = 2; i < n ; i++) {
int temp = cur;
cur += prev;
prev = temp;
}
return cur;
}
}
33 changes: 33 additions & 0 deletions valid-anagram/hoonjichoi1.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy
  • 설명: 두 문자열의 문자를 해시맵으로 세고 비교하여 아나그램 여부를 판단하는 방식으로, 해시 맵을 이용한 빈도 카운트 패턴이 핵심입니다. 특정 최적화 없이도 일치 여부를 확인하는 절차로 구성됩니다.

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

public class hoonjichoi1 {
public boolean isAnagram(String s, String t) {
if (s.equals(t))
return true;
if (s.length() != t.length())
return false;

HashMap<Character, Integer> map = new HashMap<>();

for (int i = 0; i < s.length(); i++) {
Character c = s.charAt(i);
map.put(c, map.getOrDefault(c, 0) + 1);
}

for (int j = 0; j < t.length(); j++) {
Character c = t.charAt(j);
if (!map.containsKey(c) || map.get(c) <= 0) {
return false;
}

map.put(c, map.get(c) - 1);
}
Comment thread
Hoonjichoi1 marked this conversation as resolved.

for (Integer i : map.values()) {
if (i < 0) {
return false;
}
}
Comment on lines +26 to +30

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.

이 반복문은 2번째 반복문에서 처리해줘도 좋을 듯 싶습니다..!

return true;
}
}
Loading