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
40 changes: 40 additions & 0 deletions linked-list-cycle/hyeri0903.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Fast & Slow Pointers
  • 설명: 이 코드는 두 포인터를 이용해 리스트를 순회하며 만나는 지점을 찾는 방식으로, 순환 여부를 판단하는 Fast & Slow Pointers 패턴에 속합니다.

📊 시간/공간 복잡도 분석

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

피드백: 포인터 두 개를 이용하여 리스트를 한 번 순회하며 만나는지 체크하는 방식으로, 리스트 길이에 비례하는 시간 복잡도를 갖고, 추가 공간은 상수입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public boolean hasCycle(ListNode head) {
/**
1.prob: linked list 이면 true, 아니면 false return
2.constraints
- # of nodes min = 0, max = 10000
- pos: -1 or valid index
- pos는 파라미터로 받지 않음
3.solution
- pointer 2개를 두고 1개는 2칸씩, 1개는 1칸씩 이동하며 결국 만나는지 체크
만나면 true, 안 만나면 false return
*/

ListNode slow = head;
ListNode fast = head;

while(fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;

//노드가 동일하면 linked list
if(slow == fast) {
return true;
}
}
return false;

}
}
43 changes: 43 additions & 0 deletions maximum-product-subarray/hyeri0903.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, Two Pointers
  • 설명: 이 코드는 현재 위치까지의 최대, 최소 곱을 추적하며 최적의 부분배열을 찾는 방식으로, DP와 투 포인터 개념이 결합된 패턴입니다. 연속된 배열 내에서 최적 값을 계산하는 특성상 두 패턴이 적합합니다.

📊 시간/공간 복잡도 분석

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

피드백: 한 번의 순회로 최대값과 최소값을 갱신하며, 각 요소마다 상수 시간 연산을 수행하므로 선형 시간입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Solution {
public int maxProduct(int[] nums) {
/**
1.problem: subarray 중에 가장 큰 product return
2.constraints
- num.length min = 1
- value min = -10, max=10
3.solutions
- bruteforce, time: O(n^2), space: O(1)
- min, max value 추적, time: O(n), space: O(1)
*/
int n = nums.length;
if (n == 1) return nums[0];

// int maxValue = Integer.MIN_VALUE;
// for(int i = 0; i < n; i++) {
// int curValue = 1;
// for(int j = i; j < n; j++) {
// curValue *= nums[j];
// maxValue = Math.max(maxValue, curValue);
// }
// }

int max = nums[0];
int min = nums[0];
int res = nums[0];

for(int i = 1; i < n; i++) {
int cur = nums[i];
//현재값이 음수이면 min, max swap
if(cur < 0) {
int tmp = min;
min = max;
max = tmp;
}
max = Math.max(cur, max * cur);
min = Math.min(cur, min * cur);

res = Math.max(max, res);
}
return res;
}
}
66 changes: 66 additions & 0 deletions minimum-window-substring/hyeri0903.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Sliding Window, Hash Map / Hash Set
  • 설명: 이 코드는 두 포인터를 이용한 슬라이딩 윈도우 기법으로, 문자 빈도수 추적을 위해 해시 맵을 사용하여 최소 길이의 부분 문자열을 찾는 문제에 적합합니다.

📊 시간/공간 복잡도 분석

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

피드백: 문자 빈도수 배열과 두 포인터를 활용하여 문자열을 한 번씩 이동하며 조건을 만족하는 최소 구간을 찾는 방식으로, 시간 복잡도는 문자열 길이의 합입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class Solution {
public String minWindow(String s, String t) {
/**
1.prob: t문자를 포함하는 최소 길이의 substring return.
2.constraints
- 정답은 단 1개
- t의 모든 문자를 포함
- m,n length min = 1, max = 100000
- s,t 는 uppercase or lowercase
- 정답 없으면 emptystring "" return
3.solution
- brutforce, 모든 substring 구해서 t문자 포함 여부 체크, time complexity: O(n^2)
- two pointer: right pointer 움직이다가 t문자 모두 포함하면 left pointer 옮기면서 가장 작은 사이즈의 substring 구하기, time compliexty: O(m+n), space: O(1)
힌트 봐도 모르겠어서 풀이보고 풀었습니다 ㅜㅜ
*/

int m = s.length();
int n = t.length();
String answer = "";

if(m < n) return "";

int left = 0, right = 0;
int count = n; //필요한 문자 수 = t.length()
int minLen = Integer.MAX_VALUE;
int start = 0; //조건 만족하는 left pointer 시작 포인트

int[] freq = new int[128];
for(char c : t.toCharArray()) {
freq[c]++;
}

while(right < m) {
char r = s.charAt(right);
//t 문자면 count--
if(freq[r] > 0) {
count --;
}
freq[r]--;
right++;

//조건 만족하면 left pointer 이동하며 minimum length 찾음
while(count == 0) {
//minLen update
if(right - left < minLen) {
minLen = right - left;
start = left; //minLen 업데이트 시 Left pointer index 저장
}
char l = s.charAt(left);
freq[l]++;

//t문자(필요한 문자)이면 count 증가 (원래 값으로 복구)
if(freq[l] > 0) count++;
left++;
}

}

if(minLen == Integer.MAX_VALUE) {
answer = "";
} else {
answer = s.substring(start, start + minLen);
}
return answer;
}
}
53 changes: 53 additions & 0 deletions pacific-atlantic-water-flow/hyeri0903.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: DFS
  • 설명: 이 코드는 깊이 우선 탐색(DFS)을 사용하여 각각의 바다에서 도달 가능한 칸을 찾고, 교차하는 칸을 구하는 방식으로 문제를 해결합니다.

📊 시간/공간 복잡도 분석

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

피드백: 각 칸에 대해 DFS를 수행하며, 전체 맵 크기만큼 방문 체크를 하므로 시간과 공간 모두 맵 크기에 비례합니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class Solution {
int[][] dirs = {{1,0}, {-1,0}, {0,1}, {0,-1}};

public List<List<Integer>> pacificAtlantic(int[][] heights) {
/**
1.2개의 ocean 모두로 도달할 수 있는 칸들을 찾는 문제
2.height 높은 곳 -> 낮은 곳으로 이동
time, space: O(mn)
*/
int m = heights.length;
int n = heights[0].length;
boolean[][] pacific = new boolean[m][n];
boolean[][] atlantic = new boolean[m][n];

List<List<Integer>> answer = new ArrayList<>();

for(int i = 0; i < m; i++) {
dfs(i, 0, m, n, heights, pacific);
dfs(i, n-1, m, n, heights, atlantic);
}
for(int j = 0; j < n; j++) {
dfs(0, j, m, n, heights, pacific);
dfs(m-1, j, m, n, heights, atlantic);
}

for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
if(pacific[i][j] && atlantic[i][j]) {
answer.add(Arrays.asList(i,j));
}
}
}
return answer;
}

void dfs(int i, int j, int m, int n, int[][] heights, boolean[][] visited) {
if(i < 0 || i >= m || j < 0 || j >= n || visited[i][j]) {
return;
}

visited[i][j] = true;
for(int[] d: dirs) {
int nexti = i + d[0];
int nextj = j + d[1];

//범위 안 && 방문 안했고 && 높이 조건 만족하면 다음 루트 탐색
if(nexti >= 0 && nexti < m && nextj >= 0 && nextj < n && !visited[nexti][nextj] && heights[nexti][nextj] >= heights[i][j]) {
dfs(nexti, nextj, m, n, heights, visited);
}

}
}
}
18 changes: 18 additions & 0 deletions sum-of-two-integers/hyeri0903.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
  • 설명: 이 코드는 비트 연산을 활용하여 두 정수의 합을 구하는 방법으로, 자리 올림 계산에 비트 연산을 사용합니다.

📊 시간/공간 복잡도 분석

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

피드백: 반복문이 비트 연산을 통해 자리 올림과 합을 처리하며, 최대 자리수는 정수 크기 제한으로 상수입니다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int getSum(int a, int b) {
/**
1.operator 을 쓰지않고 two sum 구하는 문제
2.constraints
- without using operators + and -
- value min = -1000, max = 1000
3.solution
-bit 연산
*/
while (b != 0) {
int carry = (a & b) << 1; // 자리 올림
a = a ^ b; // 자리 올림 없는 합
b = carry; // 다음에 더할 carry
}
return a;
}
}
Loading