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
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
  • 설명: 백트래킹으로 가능한 숫자 조합을 탐색하며 남은 합을 줄여가고, 조건에 맞으면 결과에 추가하는 구조로 구현되어 있습니다. 중복 허용 여부를 제어하며 재귀 호출로 모든 조합을 탐색합니다.

📊 시간/공간 복잡도 분석

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

피드백: 백트래킹으로 각 후보를 재귀적으로 선택하거나 선택하지 않으며, 중복 없이 시작 인덱스(start)로 조합을 구성합니다.

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

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

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);

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.

removeLast() 사용하셔도 될 것 같습니다

}
}
}
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의 개수를 세는 문제로, 비트 조작(Binary/Bit Manipulation) 패턴에 해당합니다.

📊 시간/공간 복잡도 분석

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

피드백: Java의 내장 메서드 Integer.bitCount를 이용해 비트를 셉니다.

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

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

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);

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.

bitCount로 바로 풀리긴 하는데 알고리즘 풀이 목적으로는 직접 구현해보시는게 좋을 것 같아요. 추가로 bitCount에 대한 내부 구현도 안 보셨다면 이해해보시면 좋을 것 같습니다.


// 추가 풀이.
// 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, Greedy
  • 설명: 문자열에서 문자만 추출하고 소문자로 변환한 뒤 반대편과 비교하여 대칭인지 확인하므로 Two Pointers 패턴에 해당합니다. 보조로 문자열 정리에 StringBuilder를 사용한 것은 효율적 문자열 조작의 일반적 기법이며, 대칭 비교 자체가 특정 해시나 최적화 없이 좌우를 비교하는 형태라 Hash Map/Hash Set이나 Greedy의 핵심은 아니지만 보조적으로 보일 수 있습니다.

📊 시간/공간 복잡도 분석

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

피드백: 필터링과 정규화 후 양 끝에서 대칭 비교로 팰린드롬 여부를 판단합니다.

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

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

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));
}
}
Comment on lines +3 to +8

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.

StringBuilder를 쓰셨군요. 이 방식은 공간 복잡도 O(n) 을 필요로 하는데요. 별도의 공간을 사용하지 않고 투 포인터로도 풀어보셔도 좋을 거 같습니다.


String result = sb.toString();
char[] x = result.toCharArray();
Comment on lines +10 to +11

@parkhojeong parkhojeong Jul 14, 2026

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.

result 변수는 인라인 해도 될 거 같습니다.

for (int i = 0; i < x.length / 2; i++) {
if (x[i] != x[x.length - i - 1]) {
return false;
}
}

@parkhojeong parkhojeong Jul 14, 2026

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.

변수명 x는 가독성이 안 좋아서 의미 있는 이름을 사용하시는게 좋을 거 같습니다.

return true;
}
}
Loading