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
35 changes: 35 additions & 0 deletions combination-sum/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Backtracking, Depth-First Search, Greedy
  • 설명: 깊이 우선 탐색으로 후보를 하나씩 선택해 합이 타겟에 도달하는지 재귀적으로 탐색하며, 조건 충족 시 현재 선택 조합을 저장한다. 시작 위치를 고정하고 남은 후보를 재귀로 탐색하는 백트래킹 패턴이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(k * n!)
Space O(t)

피드백: 백트래킹 없이 중복 조합 탐색이 이뤄지며, 매 재귀에서 후보를 다시 시도하므로 지수적 시간 복잡도가 예상됩니다.

개선 제안: 고려해볼 만한 대안: 가지치기와 중복 제거를 명시적으로 구현하고, 정렬 후 남은 후보군의 재사용 여부를 제어하면 불필요한 탐색을 줄일 수 있습니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Time Complexity : O(c^t)
Space Complexity : O(t)
*/

class Solution {

public List<List<Integer>> combinationSum(int[] candidates, int target) {
List<List<Integer>> output = new ArrayList<>();
Stack<Integer> nums = new Stack<>();
dfs (candidates, output, target, nums, 0, 0);
return output;
}

private void dfs(int[] candidates, List<List<Integer>> output, int target, Stack<Integer> nums, int start, int total) {
// base case : pass
if (target == total) {
output.add(new ArrayList<>(nums));
return;
}
// base case : fail
if (target < total) {
return;
}

for (int i = start ; i < candidates.length ; i++) {
int num = candidates[i];
nums.push(num);
dfs(candidates, output, target, nums, i, total + num);
nums.pop();
}


}
}
19 changes: 19 additions & 0 deletions number-of-1-bits/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Bit Manipulation, Greedy, Divide and Conquer
  • 설명: 주어진 코드는 정수를 2진수로 나눠 1의 개수를 세는 방식으로 비트 수를 구한다. 비트 조작 대신 나눗셈/나머지로 2진 표현의 각 자리수를 확인하는 패턴은 Bit Manipulation과 반복적 탐색의 일종으로 해석될 수 있다.

📊 시간/공간 복잡도 분석

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

피드백: 루프는 비트 길이만큼 반복되며, 각 반복에서 나눗셈으로 비트를 확인하는 방식입니다.

개선 제안: 현재 구현은 특정 초기 조건 비효율이 있습니다. 비트를 오른쪽으로 시프트하고 1인 경우 카운트를 증가시키면 더 직관적이고 일반적인 풀이가 됩니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public int hammingWeight(int n) {

if (n == 1) {
return 1;
}

int curr = n, result = 1;
while (curr > 1) {
if (curr % 2 == 1) {
result++;
}
curr = curr / 2;
}

return result;
}
}

23 changes: 23 additions & 0 deletions valid-palindrome/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Greedy
  • 설명: 문자열을 정리한 뒤 좌우 포인터를 동시에 움직이며 대칭 여부를 비교하므로 Two Pointers 패턴에 해당합니다. 또한 효율적인 비교를 위해 한 방향으로 좁혀 가는 방식은 간단한 Greedy 맥락으로도 해석될 수 있습니다.

📊 시간/공간 복잡도 분석

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

피드백: 정규식으로 한 번 필터링하고 양방향 탐색으로 대칭 여부를 확인합니다.

개선 제안: 현재 구현의 변수명 오타(conveted) 등 리팩토링으로 가독성을 높이고, 필요한 경우 스트림이나 투포인터 방식으로 불필요한 문자열 생성 없이도 구현할 수 있습니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
public boolean isPalindrome(String s) {

// removing all non-alphanumeric characters and convert them to lower case
String conveted = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();

// early return of the empty string case
if (conveted.length() == 0) {
return true;
}

// check the symmetry
int left = 0, right = conveted.length() - 1;
while (left <= right) {
if (conveted.charAt(left) != conveted.charAt(right)) {
return false;
}
left++;
right--;
}
return true;
}
}
Loading