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
30 changes: 30 additions & 0 deletions combination-sum/xeulbn.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
  • 설명: 재귀적으로 후보들을 선택해 합이 target이 되도록 조합을 만드는 과정으로, 각 후보를 재사용 가능하게 두고(인덱스 i를 유지) 탐색 공간을 탐색하는 전형적인 백트래킹 풀이입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(k * C)
Space O(target * n)

피드백: 중복 제거를 위해 시작 인덱스를 유지하고 현재 부분해를 업데이트하며 백트래킹한다.

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

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

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

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

backtrack(candidates, target, 0, new ArrayList<>(), result);

return result;
}

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

if (remain < 0) {
return;
}

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

current.add(candidate);
backtrack(candidates, remain - candidate, i, current, result);
current.remove(current.size() - 1);
}
Comment on lines +22 to +28

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를 사용하시면 add -> remove 흐름을 좀더 직관적으로 나타낼 수 있을 거 것 같네요!

Suggested change
for (int i=start; i<candidates.length; i++) {
int candidate = candidates[i];
current.add(candidate);
backtrack(candidates, remain - candidate, i, current, result);
current.remove(current.size() - 1);
}
for (int i=start; i<candidates.length; i++) {
int candidate = candidates[i];
current.add(candidate);
backtrack(candidates, remain - candidate, i, current, result);
current.removeLast();
}

}
}

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.

백트래킹으로 해결하셨군요...! 많이 배워갑니다 😊

29 changes: 29 additions & 0 deletions decode-ways/xeulbn.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, Binary Search
  • 설명: 해당 코드는 문자열을 분할하는 경우의 수를 DP 배열로 누적 합산하는 전형적인 DP 패턴입니다. 연속 두 자리로 묶는 경우를 고려하는 부분은 최적해를 하위 문제의 해로 표현하는 대표적인 DP 예시입니다.

📊 시간/공간 복잡도 분석

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

피드백: 연속 부분 문제를 dp 배열로 해결하며 두 가지 상태만 고려한다.

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

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

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

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

dp[0] = 1;

dp[1] = s.charAt(0) == '0' ? 0 : 1;

for (int i=2; i<=n; i++) {
char current = s.charAt(i - 1);

if (current != '0') {
dp[i] += dp[i - 1];
}
int twoDigit =
(s.charAt(i - 2) - '0') * 10
+ (s.charAt(i - 1) - '0');
Comment on lines +18 to +20

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.

substring 을 사용하면 좀 더 직관적일 수 있을 거 같아서 고려해보시면 좋을 거 같습니다 !

Suggested change
int twoDigit =
(s.charAt(i - 2) - '0') * 10
+ (s.charAt(i - 1) - '0');
int twoDigit = Integer.parseInt(s.substring(i - 2, i));


if (twoDigit >= 10 && twoDigit <= 26) {
dp[i] += dp[i - 2];
}
}

return dp[n];
}
}
21 changes: 21 additions & 0 deletions maximum-subarray/xeulbn.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy
  • 설명: 연속 부분 배열의 합의 최댓값을 구하는 문제로, 각 위치에서 부분해의 최댓값을 유지하며 현재 값과 비교해 더 큰 쪽으로 선택하는 접근이 특징이다. Kadane 알고리즘의 핵심 아이디어로 최적해를 단순한 선형 탐색으로 구한다.

📊 시간/공간 복잡도 분석

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

피드백: 현재 배열을 한 번씩 읽으며 최댓값을 갱신한다.

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

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

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

class Solution {
public int maxSubArray(int[] nums) {
int currentSum = nums[0];
int maxSum = nums[0];

for (int i=1; i<nums.length; i++) {
if (nums[i] > currentSum + nums[i]) {
currentSum = nums[i];
} else {
currentSum += nums[i];
}

if (currentSum > maxSum) {
maxSum = currentSum;
}
}
return maxSum;
}
}
17 changes: 17 additions & 0 deletions number-of-1-bits/xeulbn.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의 개수를 셈. 비트 조작 연산과 시프트를 활용한 간단한 비트 카운팅으로 목적을 달성합니다.

📊 시간/공간 복잡도 분석

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

피드백: 입력 n의 비트 길이에 비례하는 시간으로 동작한다.

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

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

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

class Solution {
public int hammingWeight(int n) {
int count = 0;

while (n > 0) {
if ((n & 1) == 1) {
count++;
}

n = n >> 1;
}

return count;
}
}

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.

비트 연산을 활용해서 해결하셨군요! 찾아보니 이런 것을 Hamming이라고 하는 것 같네요

32 changes: 32 additions & 0 deletions valid-palindrome/xeulbn.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
  • 설명: 문자열의 좌우를 포인터로 이동하며 비교하는 투 포인터 패턴으로 회문 여부를 판단합니다. 불필요 문자 건너뛰기와 소문자 비교를 통해 선형 시간에 해결합니다.

📊 시간/공간 복잡도 분석

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

피드백: 공백 및 특수문자는 건너뛰고 소문자 비교를 수행한다.

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

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

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

class Solution {
public boolean isPalindrome(String s) {
int left =0;
int right = s.length()-1;

while (left < right) {

while (left < right && !Character.isLetterOrDigit(s.charAt(left))) {
left++;
}

while (left < right && !Character.isLetterOrDigit(s.charAt(right))) {
right--;
}

char leftChar = Character.toLowerCase(s.charAt(left));
char rightChar = Character.toLowerCase(s.charAt(right));

if (leftChar != rightChar) {
return false;
}

left++;
right--;
}


return true;
}
}

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.

저도 정확히 똑같이 풀었습니다! 사실 배열을 활용할까 했었는데, 투 포인터를 사용하는 것이 문제 의도랑 맞는 것 같네요

Loading