From ed315ea8aae2f532ccd0f92bdf8c021f5d490835 Mon Sep 17 00:00:00 2001 From: JeonJe <43032391+JeonJe@users.noreply.github.com> Date: Wed, 5 Aug 2026 21:10:50 +0900 Subject: [PATCH 1/5] reverse linked list solution --- reverse-linked-list/JeonJe.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 reverse-linked-list/JeonJe.java diff --git a/reverse-linked-list/JeonJe.java b/reverse-linked-list/JeonJe.java new file mode 100644 index 0000000000..fcacc39f20 --- /dev/null +++ b/reverse-linked-list/JeonJe.java @@ -0,0 +1,19 @@ +import java.util.*; + +// TC: O(n) +// SC: O(1) +class Solution { + public ListNode reverseList(ListNode head) { + ListNode prev = null; + ListNode cur = head; + + while (cur != null) { + ListNode temp = cur.next; + cur.next = prev; + prev = cur; + cur = temp; + } + + return prev; + } +} From 593028b821a1a6f8c89b6cfa2dc83a78243e6d38 Mon Sep 17 00:00:00 2001 From: JeonJe <43032391+JeonJe@users.noreply.github.com> Date: Wed, 5 Aug 2026 22:00:55 +0900 Subject: [PATCH 2/5] longest substring without repeating characters solution --- .../JeonJe.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 longest-substring-without-repeating-characters/JeonJe.java diff --git a/longest-substring-without-repeating-characters/JeonJe.java b/longest-substring-without-repeating-characters/JeonJe.java new file mode 100644 index 0000000000..017ea650aa --- /dev/null +++ b/longest-substring-without-repeating-characters/JeonJe.java @@ -0,0 +1,27 @@ +import java.util.*; + +// TC: O(n) +// SC: O(min(n, m)) (m = 문자 집합 크기) +class Solution { + public int lengthOfLongestSubstring(String s) { + + int answer = 0; + int left = 0; + + Set temp = new HashSet<>(); + + for (int right = 0; right < s.length(); right++) { + + // 중복이 사라질 때까지 s[left]를 set에서 빼며 left를 전진시킨다. + while (temp.contains(s.charAt(right))) { + temp.remove(s.charAt(left)); + left++; + } + + temp.add(s.charAt(right)); + answer = Math.max(answer, right - left + 1); + } + + return answer; + } +} From 56edbaf9794114a8a433e42eec2b129938699037 Mon Sep 17 00:00:00 2001 From: JeonJe <43032391+JeonJe@users.noreply.github.com> Date: Thu, 6 Aug 2026 13:55:27 +0900 Subject: [PATCH 3/5] number of islands solution --- number-of-islands/JeonJe.java | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 number-of-islands/JeonJe.java diff --git a/number-of-islands/JeonJe.java b/number-of-islands/JeonJe.java new file mode 100644 index 0000000000..53d942dca0 --- /dev/null +++ b/number-of-islands/JeonJe.java @@ -0,0 +1,44 @@ +import java.util.*; + +// TC: O(m * n) +// SC: O(m * n) +class Solution { + + private static int[] dx = {0, -1, 0, 1}; + private static int[] dy = {1, 0, -1, 0}; + + private int n = 0; + private int m = 0; + + public int numIslands(char[][] grid) { + n = grid[0].length; + m = grid.length; + + boolean[][] visited = new boolean[m][n]; + + int answer = 0; + + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (!visited[i][j] && grid[i][j] == '1') { + answer++; + dfs(i, j, grid, visited); + } + } + } + return answer; + } + + private void dfs(int x, int y, char[][] grid, boolean[][] visited) { + visited[x][y] = true; + + for (int i = 0; i < 4; i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + + if (0 <= nx && nx < m && 0 <= ny && ny < n && grid[nx][ny] == '1' && !visited[nx][ny]) { + dfs(nx, ny, grid, visited); + } + } + } +} From 56488ba565b007a3722db71e76955de3848179ad Mon Sep 17 00:00:00 2001 From: JeonJe <43032391+JeonJe@users.noreply.github.com> Date: Thu, 6 Aug 2026 22:21:05 +0900 Subject: [PATCH 4/5] unique paths solution --- unique-paths/JeonJe.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 unique-paths/JeonJe.java diff --git a/unique-paths/JeonJe.java b/unique-paths/JeonJe.java new file mode 100644 index 0000000000..8c5033baae --- /dev/null +++ b/unique-paths/JeonJe.java @@ -0,0 +1,28 @@ +import java.util.*; + +// TC: O(m * n) +// SC: O(m * n) +class Solution { + public int uniquePaths(int m, int n) { + + int[][] arr = new int[m][n]; + + int upSide; + int leftSide; + + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + if (i == 0 && j == 0) { + arr[i][j] = 1; + continue; + } + + upSide = i - 1 < 0 ? 0 : arr[i - 1][j]; + leftSide = j - 1 < 0 ? 0 : arr[i][j - 1]; + arr[i][j] = upSide + leftSide; + } + } + + return arr[m - 1][n - 1]; + } +} From 7508064befe8ddbb6dc70bb6665c0b1646ee28a2 Mon Sep 17 00:00:00 2001 From: JeonJe <43032391+JeonJe@users.noreply.github.com> Date: Thu, 6 Aug 2026 22:28:35 +0900 Subject: [PATCH 5/5] unique paths 1d dp --- unique-paths/JeonJe.java | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/unique-paths/JeonJe.java b/unique-paths/JeonJe.java index 8c5033baae..f4f0cf3b38 100644 --- a/unique-paths/JeonJe.java +++ b/unique-paths/JeonJe.java @@ -1,28 +1,19 @@ import java.util.*; // TC: O(m * n) -// SC: O(m * n) +// SC: O(n) class Solution { public int uniquePaths(int m, int n) { - int[][] arr = new int[m][n]; + int[] arr = new int[n]; + Arrays.fill(arr, 1); - int upSide; - int leftSide; - - for (int i = 0; i < m; i++) { - for (int j = 0; j < n; j++) { - if (i == 0 && j == 0) { - arr[i][j] = 1; - continue; - } - - upSide = i - 1 < 0 ? 0 : arr[i - 1][j]; - leftSide = j - 1 < 0 ? 0 : arr[i][j - 1]; - arr[i][j] = upSide + leftSide; + for (int i = 1; i < m; i++) { + for (int j = 1; j < n; j++) { + arr[j] = arr[j] + arr[j - 1]; } } - return arr[m - 1][n - 1]; + return arr[n - 1]; } }