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
32 changes: 32 additions & 0 deletions combination-sum/essaysir.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
  • 설명: 백트래킹으로 모든 조합을 탐색하여 합이 target이 되는 경우를 찾는 풀이이며, 재귀적으로 남은 합을 줄이고 시작 인덱스를 고정해 중복 없이 조합을 생성합니다. DFS 형태의 탐색 패턴과 함께 불필요한 가지를 제거하는 백트래킹 특징이 뚜렷합니다.

📊 시간/공간 복잡도 분석

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

피드백: 백트래킹으로 중복 없이 가능한 조합을 생성하며, remain이 0이 되면 현재 경로를 결과에 추가한다.

개선 제안: 현재 구현은 입력 크기에 대해 지수 시간 복잡도를 가지나, 정렬 및 가지치기(예: 남은 합이 남은 최대 가능 합보다 작은 경우)가 적용되면 실무에서 실용적일 수 있다.

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

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

class Solution {
public List<List<Integer>> combinationSum(int[] candidates, int target) {
// 합이 target 이 되는 경우의 수를 모두 고르시오
// target 이 150 이하
List<List<Integer>> result = new ArrayList<>();
List<Integer> current = new ArrayList<>();

backTracking(candidates, target, 0 , result, current);
return result;
}

public void backTracking(int[] candidates, int remain, int start, List<List<Integer>> result, List<Integer> current) {
if ( remain == 0 ){
result.add(new ArrayList<>(current));
return;
}

if ( remain < 0 ){
return;
}

for (int i = start; i < candidates.length; i++) {
current.add(candidates[i]);

backTracking(candidates, remain - candidates[i], i , result, current);

current.remove(current.size() - 1);
}
}
}
11 changes: 11 additions & 0 deletions number-of-1-bits/essaysir.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
  • 설명: 주어진 코드는 정수의 이진 표현에서 1의 개수를 세는 작업으로, 비트 조작 함수인 bitCount를 활용합니다. 직접적인 비트 연산 구현은 아니지만 비트 조작과 관련된 패턴에 해당합니다.

📊 시간/공간 복잡도 분석

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

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

피드백: 주어진 정수의 1비트를 세는 방법으로 간단하고 빠르게 해결된다.

개선 제안: 추가 구현은 필요 없고, 내장 함수 사용이 가장 간단하고 효율적이다.

풀이 2: Solution.hammingWeight — Time: O(b) / Space: O(1)
복잡도
Time O(b)
Space O(1)

피드백: 비트 길이에 비례하는 시간이며, 문자열 변환이 비용으로 추가된다.

개선 제안: 권장 구현은 비트카운트 내장 함수를 사용하는 방법이다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution {
public int hammingWeight(int n) {
// 이진수로 바꾸고, 1 이 몇개 있는 지 파악한다.
return Integer.bitCount(n);

// 추가 풀이.
// String ans = Integer.toBinaryString(n).replace("0","");
// return ans.length();
}
}

19 changes: 19 additions & 0 deletions valid-palindrome/essaysir.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, Hash Map / Hash Set
  • 설명: 문자열 전처리 후 양 끝에서 비교하는 방식으로 대칭 여부를 확인하므로 Two Pointers 패턴이 핵심입니다. Hash Map/Hash Set은 사용되진 않지만 문자 구성 확인 및 비교를 위해 중간에 문자열을 정규화하는 과정이 포함됩니다. 전체적으로 isPalindrome 판단 로직에 해당합니다.

📊 시간/공간 복잡도 분석

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

피드백: 무작정 대소문자 무시 및 비문자 제거를 통해 문제 정의에 맞춘 간단한 풀이이다.

개선 제안: 공간 사용을 줄이고 in-place 처리를 원하면 두 포인터를 사용해 스캔하며 제거된 문자 여부를 판단하는 방법도 가능하다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public boolean isPalindrome(String s) {
StringBuilder sb = new StringBuilder();
for (char c : s.toCharArray()) {
if (Character.isLetterOrDigit(c)) {
sb.append(Character.toLowerCase(c));
}
}

String result = sb.toString();
char[] x = result.toCharArray();
for (int i = 0; i < x.length / 2; i++) {
if (x[i] != x[x.length - i - 1]) {
return false;
}
}
return true;
}
}
Loading