From a4312007f624508e7fb97e81af4edae180f90545 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Thu, 16 Apr 2026 23:32:07 +0900 Subject: [PATCH 1/6] number of islands solution --- number-of-islands/hyeri0903.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/number-of-islands/hyeri0903.py b/number-of-islands/hyeri0903.py index be6028160..36a8bc34f 100644 --- a/number-of-islands/hyeri0903.py +++ b/number-of-islands/hyeri0903.py @@ -6,7 +6,6 @@ def numIslands(self, grid: List[List[str]]) -> int: ''' m = len(grid) n = len(grid[0]) - visited = [ [0] * n for _ in range(m)] count = 0 def dfs(i, j): @@ -14,10 +13,10 @@ def dfs(i, j): if i < 0 or i >= m or j < 0 or j >= n or grid[i][j] == "0": return - if visited[i][j] == 1: + if grid[i][j] == "#": return - - visited[i][j] = 1 #방문표시 + #방문표시 + grid[i][j] = "#" dfs(i+1, j) dfs(i-1, j) @@ -26,7 +25,7 @@ def dfs(i, j): for i in range(m): for j in range(n): - if grid[i][j] == "1" and visited[i][j] == 0: + if grid[i][j] == "1" and grid[i][j] != "#": dfs(i,j) count += 1 return count From 3e704ff665820113852025fc441be97684268ce3 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Thu, 16 Apr 2026 23:43:03 +0900 Subject: [PATCH 2/6] reverse linked list solutions --- reverse-linked-list/hyeri0903.java | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 reverse-linked-list/hyeri0903.java diff --git a/reverse-linked-list/hyeri0903.java b/reverse-linked-list/hyeri0903.java new file mode 100644 index 000000000..456b6ec8a --- /dev/null +++ b/reverse-linked-list/hyeri0903.java @@ -0,0 +1,36 @@ +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode() {} + * ListNode(int val) { this.val = val; } + * ListNode(int val, ListNode next) { this.val = val; this.next = next; } + * } + */ +class Solution { + public ListNode reverseList(ListNode head) { + if(head == null) { + return null; + } + + Deque stack = new ArrayDeque<>(); + ListNode node = head; + + while(node != null) { + stack.push(node.val); + node = node.next; + } + + ListNode dummy = new ListNode(); + ListNode cur = dummy; + + while(stack.size() > 0) { + int val = stack.pop(); + cur.next = new ListNode(val); + cur = cur.next; + } + + return dummy.next; + } +} From 9cd063a7a5e2675abfe0e4af864e8c895d9598c4 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Thu, 16 Apr 2026 23:56:21 +0900 Subject: [PATCH 3/6] number of islands solution --- number-of-islands/hyeri0903.java | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 number-of-islands/hyeri0903.java diff --git a/number-of-islands/hyeri0903.java b/number-of-islands/hyeri0903.java new file mode 100644 index 000000000..bb24a3a98 --- /dev/null +++ b/number-of-islands/hyeri0903.java @@ -0,0 +1,43 @@ +class Solution { + + public int numIslands(char[][] grid) { + /** + 1.prob:섬 개수 구하기 + 2.constraints: + - 원소값 0 or 1 + - m,n 길이는 최소 = 1, 최대 = 300 + 3.solution: dfs + */ + + //m: 세로, n: 가로 길이 + int m = grid.length; + int n = grid[0].length; + int count = 0; + + for(int i = 0; i < m; i++) { + for(int j = 0; j < n; j++) { + if(grid[i][j] == '1' && grid[i][j] != '#') { + dfs(i, j, grid, m, n); + count += 1; + } + } + } + return count; + } + void dfs(int i, int j, char[][] grid, int m, int n) { + if(i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == '0') { + return; + } + //이미 visited + if(grid[i][j] == '#') { + return; + } + //방문 체크 + grid[i][j] = '#'; + + dfs(i+1, j, grid, m, n); + dfs(i-1, j, grid, m, n); + dfs(i, j+1, grid, m, n); + dfs(i, j-1, grid, m, n); + } +} From f48c4b56d717ab778533682da6dd79b6ef307d0a Mon Sep 17 00:00:00 2001 From: hyerijung Date: Fri, 17 Apr 2026 00:13:13 +0900 Subject: [PATCH 4/6] lengthOfLongestSubstring solution --- .../hyeri0903.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 longest-substring-without-repeating-characters/hyeri0903.java diff --git a/longest-substring-without-repeating-characters/hyeri0903.java b/longest-substring-without-repeating-characters/hyeri0903.java new file mode 100644 index 000000000..ecf404f82 --- /dev/null +++ b/longest-substring-without-repeating-characters/hyeri0903.java @@ -0,0 +1,28 @@ +class Solution { + public int lengthOfLongestSubstring(String s) { + /** + 1.prob: 중복없는 가장 긴 substring length return + 2.constraints: + - alphabet, digit, space 로 구성 + - s.length min = 0, max = 50,000 + 3.solution + - slding window, time: O(n), space: O(n) or O(1) + */ + + int maxLen = 0; + int left = 0; + Set visited = new HashSet<>(); + + for(int i = 0; i < s.length(); i++){ + char ch = s.charAt(i); + while(visited.contains(ch)) { + visited.remove(s.charAt(left)); + left += 1; + } + visited.add(ch); + maxLen = Math.max(maxLen, i - left + 1); + } + + return maxLen; + } +} From 4c7f657a8601ba8f976bae4135f3532da260c562 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Sat, 18 Apr 2026 18:27:37 +0900 Subject: [PATCH 5/6] unique-paths solution --- unique-paths/hyeri0903.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 unique-paths/hyeri0903.java diff --git a/unique-paths/hyeri0903.java b/unique-paths/hyeri0903.java new file mode 100644 index 000000000..df0ecf942 --- /dev/null +++ b/unique-paths/hyeri0903.java @@ -0,0 +1,33 @@ +class Solution { + public int uniquePaths(int m, int n) { + /** + 1.문제: finish로 가는 unique path 수 + 2.constraints: + - m: 세로, n = 가로 + - m,n min = 1, max = 100 + - right, down 으로만 움직이기 가능 + 3.solution + - dfs ?? => x, 모든 경로 탐색하지 않음 + - dp => [i][j] = [i-1][j] + [i][j-1] + - time: O(mn), space: O(n) + */ + + int[][] dp = new int[m][n]; + + //첫행, 첫열 = 1 + for(int i =0; i Date: Sat, 18 Apr 2026 18:40:44 +0900 Subject: [PATCH 6/6] set-matrix-zeroes solution --- set-matrix-zeroes/hyeri0903.java | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 set-matrix-zeroes/hyeri0903.java diff --git a/set-matrix-zeroes/hyeri0903.java b/set-matrix-zeroes/hyeri0903.java new file mode 100644 index 000000000..4a4697203 --- /dev/null +++ b/set-matrix-zeroes/hyeri0903.java @@ -0,0 +1,37 @@ +class Solution { + public void setZeroes(int[][] matrix) { + /** + 1.문제: 0이 존재하는 위치의 모든 row, column을 0으로 set + 2.constraints: + - m,n min = 1, max = 200 + - space: O(mn)으로 풀이하지말 것, + 3.solution + - 0의 위치를 확인 -> 0의 위치는 여러개일 수 있음 + - row, col 각각 0의 위치 저장 + - time: O(mn), space O(m+n) + */ + int m = matrix.length; + int n = matrix[0].length; + int[] row = new int[m]; //0이 존재하는 row 위치이면 1, 아니면 0 + int[] col = new int[n]; //0이 존재하는 col 위치이면 1, 아니면 0 + + int x = 0; int y = 0; //0의 위치 + + for(int i = 0; i < m; i++) { + for(int j = 0; j < n; j++) { + if(matrix[i][j] == 0) { + row[i] = 1; + col[j] = 1; + } + } + } + + for(int i = 0; i < m; i++) { + for(int j = 0; j < n; j++) { + if(row[i] == 1 || col[j] == 1) { + matrix[i][j] = 0; + } + } + } + } +}