From a42ef1d430690f957ea746c7e1ddb2e7698b47ee Mon Sep 17 00:00:00 2001 From: hyerijung Date: Mon, 27 Apr 2026 20:54:16 +0900 Subject: [PATCH 1/7] sum of two integers solution --- sum-of-two-integers/hyeri0903.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 sum-of-two-integers/hyeri0903.java diff --git a/sum-of-two-integers/hyeri0903.java b/sum-of-two-integers/hyeri0903.java new file mode 100644 index 0000000000..ac29adf173 --- /dev/null +++ b/sum-of-two-integers/hyeri0903.java @@ -0,0 +1,5 @@ +class Solution { + public int getSum(int a, int b) { + + } +} From 49d0f66bd4fe11d58abef9e9c7e972983dcedf9b Mon Sep 17 00:00:00 2001 From: hyerijung Date: Mon, 27 Apr 2026 21:05:12 +0900 Subject: [PATCH 2/7] sum of two integers solution --- sum-of-two-integers/hyeri0903.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sum-of-two-integers/hyeri0903.java b/sum-of-two-integers/hyeri0903.java index ac29adf173..43e715c3e0 100644 --- a/sum-of-two-integers/hyeri0903.java +++ b/sum-of-two-integers/hyeri0903.java @@ -1,5 +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; } } From af83cb28bef55a8c4c7234884810a5b1ad4e08b2 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Mon, 27 Apr 2026 21:19:45 +0900 Subject: [PATCH 3/7] maximum-product-subarray solution --- maximum-product-subarray/hyeri0903.java | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 maximum-product-subarray/hyeri0903.java diff --git a/maximum-product-subarray/hyeri0903.java b/maximum-product-subarray/hyeri0903.java new file mode 100644 index 0000000000..6e45f45d0e --- /dev/null +++ b/maximum-product-subarray/hyeri0903.java @@ -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; + } +} From bae3fa785347d2dca1695b3c7225a5f86a56a806 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Wed, 29 Apr 2026 20:17:42 +0900 Subject: [PATCH 4/7] linked-list-cycle solution --- linked-list-cycle/hyeri0903.java | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 linked-list-cycle/hyeri0903.java diff --git a/linked-list-cycle/hyeri0903.java b/linked-list-cycle/hyeri0903.java new file mode 100644 index 0000000000..aa1e3d2415 --- /dev/null +++ b/linked-list-cycle/hyeri0903.java @@ -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; + + } +} From a1912615884c2a55ab1c1cfd26eae2c8f44ff517 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Thu, 30 Apr 2026 09:47:01 +0900 Subject: [PATCH 5/7] minimum-window-substring solutions --- minimum-window-substring/hyeri0903.java | 66 +++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 minimum-window-substring/hyeri0903.java diff --git a/minimum-window-substring/hyeri0903.java b/minimum-window-substring/hyeri0903.java new file mode 100644 index 0000000000..93fb67423a --- /dev/null +++ b/minimum-window-substring/hyeri0903.java @@ -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(n) + 힌트 봐도 모르겠어서 풀이보고 풀었습니다 ㅜㅜ + */ + + 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; + } +} From 26f755cb27d30be14c113633ce2b116890aadde4 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Thu, 30 Apr 2026 09:47:59 +0900 Subject: [PATCH 6/7] minimum-window-substring solutions --- minimum-window-substring/hyeri0903.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minimum-window-substring/hyeri0903.java b/minimum-window-substring/hyeri0903.java index 93fb67423a..a8b4d3cbc3 100644 --- a/minimum-window-substring/hyeri0903.java +++ b/minimum-window-substring/hyeri0903.java @@ -10,7 +10,7 @@ public String minWindow(String s, String t) { - 정답 없으면 emptystring "" return 3.solution - brutforce, 모든 substring 구해서 t문자 포함 여부 체크, time complexity: O(n^2) - - two pointer: right pointer 움직이다가 t문자 모두 포함하면 left pointer 옮기면서 가장 작은 사이즈의 substring 구하기, time compliexty: O(n) + - two pointer: right pointer 움직이다가 t문자 모두 포함하면 left pointer 옮기면서 가장 작은 사이즈의 substring 구하기, time compliexty: O(m+n), space: O(1) 힌트 봐도 모르겠어서 풀이보고 풀었습니다 ㅜㅜ */ From fb649e93c626fc9616073bb76b207c5977b9e343 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Sat, 2 May 2026 09:27:02 +0900 Subject: [PATCH 7/7] pacific-atlantic-water-flow solution --- pacific-atlantic-water-flow/hyeri0903.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 pacific-atlantic-water-flow/hyeri0903.java diff --git a/pacific-atlantic-water-flow/hyeri0903.java b/pacific-atlantic-water-flow/hyeri0903.java new file mode 100644 index 0000000000..0dbb2c3d32 --- /dev/null +++ b/pacific-atlantic-water-flow/hyeri0903.java @@ -0,0 +1,53 @@ +class Solution { + int[][] dirs = {{1,0}, {-1,0}, {0,1}, {0,-1}}; + + public List> 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> 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); + } + + } + } +}