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
34 changes: 34 additions & 0 deletions combination-sum/JeonJe.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
  • 설명: 깊이 우선 탐색으로 가능한 조합을 탐색하며, 후보를 하나씩 선택/삭제하는 백트래킹 방식이 핵심이다. 조건을 만족하면 답에 추가하고, 불가능하면 가지치기하며 재귀적으로 탐색한다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n^(target/min)) O(k * n)
Space O(target/min) O(n)

피드백: 각 재귀 단계에서 남은 타깃을 초과하지 않도록 가지치기를 하고, 같은 원소를 재사용하도록 인덱스를 i로 고정된 상태에서 재귀합니다.

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

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

// TC: O(n^(target/min))
// SC: O(target/min)
class Solution {
private static List<List<Integer>> answer;

public List<List<Integer>> combinationSum(int[] candidates, int target) {
answer = new ArrayList<>();

List<Integer> bucket = new ArrayList<>();
int curSum = 0;

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.

Suggested change
int curSum = 0;

이 변수는 실제로 사용되지않는 데드코드인 것 같습니다. 없어도 될 것 같습니다!


dfs(candidates, bucket, target, 0, 0);

return answer;
}

private void dfs(int[] candidates, List<Integer> bucket, int target, int startIdx, int curSum) {
if (curSum == target) {
answer.add(new ArrayList<>(bucket));
return;
}
if (curSum > target)
return;

for (int i = startIdx; i < candidates.length; i++) {
bucket.add(candidates[i]);
dfs(candidates, bucket, target, i, curSum + candidates[i]);
bucket.removeLast();
}

}
}
24 changes: 24 additions & 0 deletions decode-ways/JeonJe.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
  • 설명: 문자열을 한 칸씩 보며 1자리/2자리 조합의 경우의 수를 누적합으로 계산하는 전형적인 계단 오르기/해석 문제 풀이로, 하위 문제의 해를 재활용하는 DP 패턴에 속합니다.

📊 시간/공간 복잡도 분석

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

피드백: 한 위치에 대해 한 자리와 두 자리를 고려하는 표준 DP 풀이

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

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

// TC: O(n)
// SC: O(n)
class Solution {
public int numDecodings(String s) {
int n = s.length();
int[] dp = new int[n + 1];
dp[n] = 1;

for (int i = s.length() - 1; i >= 0; i--) {
if (s.charAt(i) != '0') {
dp[i] = dp[i + 1];
}
if (i + 1 < n) {
int twoDigit = Integer.parseInt(s.substring(i, i + 2));
if (twoDigit >= 10 && twoDigit <= 26) {
dp[i] += dp[i + 2];
}
}
}
return dp[0];
}
}
20 changes: 20 additions & 0 deletions maximum-subarray/JeonJe.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 패턴으로 구현되어 있다. 1차원 DP 배열을 활용해 중첩된 부분문제의 해를 저장한다.

📊 시간/공간 복잡도 분석

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

피드백: 각 위치에서 뒤의 부분배열 합과 현재 값을 비교해 최댓값을 갱신하는 방식

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

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

// TC: O(n)
// SC: O(n)
class Solution {
public int maxSubArray(int[] nums) {
int n = nums.length;
int[] dp = new int[n];

dp[n - 1] = nums[n - 1];
int answer = dp[n - 1];

for (int i = n - 2; i >= 0; i--) {
dp[i] = Math.max(dp[i + 1] + nums[i], nums[i]);
answer = Math.max(answer, dp[i]);
}
Comment on lines +8 to +16

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.

직관적으로 잘 구현하신 것 같습니다. 여기서 SC를 O(1)로 최적화해볼 수 있을 것 같습니다.

현재 점화식이 참조중인 값이 이전값을 담는 것 하나라서 dp[] 대신에 int 변수를 사용해도(현재 상태 하나만으로도) 구현이 가능합니다!

Suggested change
int[] dp = new int[n];
dp[n - 1] = nums[n - 1];
int answer = dp[n - 1];
for (int i = n - 2; i >= 0; i--) {
dp[i] = Math.max(dp[i + 1] + nums[i], nums[i]);
answer = Math.max(answer, dp[i]);
}
int current_max = nums[n - 1];
int answer = current_max;
for (int i = n - 2; i >= 0; i--) {
current_max = Math.max(current_max + nums[i], nums[i]);
answer = Math.max(answer, current_max);
}


return answer;
}
}
17 changes: 17 additions & 0 deletions number-of-1-bits/JeonJe.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
  • 설명: 주어진 코드는 비트를 직접 다루며 1의 비트 수를 세는 로직으로, 비트 연산을 이용한 패턴(Bit Manipulation)을 사용합니다. 또한 매 턴 순서를 단순 반복하는 형태로 추가적인 최적화 없이 직접 비트를 확인합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(1) O(number_of_bits)
Space O(1) O(1)

피드백: 비트 단위 순회로 모든 비트를 검사해 1의 개수를 누적합니다.

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

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

// TC: O(1)
// SC: O(1)
class Solution {
public int hammingWeight(int n) {
int answer = 0;

while (n != 0) {
if ((n & 1) == 1) {
answer++;
}
Comment on lines +10 to +12

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.

이건 정말 단순한 재미 요소긴 한데요, 간단한 증감연산의 경우에는 이렇게도 표현해볼 수 있을 것 같습니다.

Suggested change
if ((n & 1) == 1) {
answer++;
}
answer += n & 1;

n = n >>> 1;
}
return answer;
}
}
23 changes: 23 additions & 0 deletions valid-palindrome/JeonJe.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, Hash Map / Hash Set
  • 설명: 문자열에서 문자만 추출해 소문자로 정렬해 하나의 문자열(sb)로 만든 뒤 양 끝에서 각 인덱스의 문자를 비교하며 대칭 여부를 확인한다. 두 포인터로 중앙까지 진행하는 전형적인 Two Pointers 패턴과 문자열 전처리 관점의 간단한 최적화가 보인다.

📊 시간/공간 복잡도 분석

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

피드백: 전처리 문자열 빌더와 양 끝 비교로 대소문자 무시 및 알파벳/숫자만 검사

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

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

// TC: O(n)
// SC: O(n)
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 +9 to +13

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.

우와, 문자를 배열로 나눠서 하나씩 비교하는 거군요. 내장함수 isLetterOrDigit()으로 쉽게 비교할 수 있는 방식인가보네요.. java는 뭔가 투박해보여도 꽤 친절한 언어인 것 같습니다!


for (int i = 0; i < sb.length() / 2; i++) {
if (sb.charAt(i) != sb.charAt(sb.length() - 1 - i)) {
return false;
}
}
return true;
}

}
Loading