From 2517fa188482327c4e1b7569b161d4264ef19eee Mon Sep 17 00:00:00 2001 From: hyerijung Date: Thu, 23 Apr 2026 20:30:43 +0900 Subject: [PATCH 1/6] longest-common-subsequence solution --- longest-common-subsequence/hyeri0903.java | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 longest-common-subsequence/hyeri0903.java diff --git a/longest-common-subsequence/hyeri0903.java b/longest-common-subsequence/hyeri0903.java new file mode 100644 index 0000000000..cced12a890 --- /dev/null +++ b/longest-common-subsequence/hyeri0903.java @@ -0,0 +1,28 @@ +class Solution { + public int longestCommonSubsequence(String text1, String text2) { + /** + 1.문제: 가장 긴 common subsequence length return, 없으면 0 return + 2.constraints + - length min = 1, max = 1000 + - text1, text2 모두 lowercase로 구성 + 3.풀이 + - dp[i][j] = text1의 앞 i개, text2의 앞 j개를 비교했을 때 LCS 길이 + - 문자가 같으면: dp[i][j] = dp[i-1][j-1] + 1 + - 문자가 다르면: dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + */ + int t1Size = text1.length(); //row + int t2Size = text2.length(); //col + int[][] dp = new int[t1Size + 1][t2Size + 1]; + + for(int i = 1; i <= t1Size; i++) { + for(int j = 1; j <= t2Size; j++) { + if(text1.charAt(i-1) == text2.charAt(j-1)) { + dp[i][j] = dp[i-1][j-1] + 1; + } else { + dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]); + } + } + } + return dp[t1Size][t2Size]; + } +} From f40ebfb53ed19e516303e0ea581adb79301feac2 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Fri, 24 Apr 2026 21:33:15 +0900 Subject: [PATCH 2/6] palindromic-substrings solutions --- palindromic-substrings/hyeri0903.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 palindromic-substrings/hyeri0903.java diff --git a/palindromic-substrings/hyeri0903.java b/palindromic-substrings/hyeri0903.java new file mode 100644 index 0000000000..e69de29bb2 From 8c9defe98ae3b5e3098ec96265d04fd29b268b3a Mon Sep 17 00:00:00 2001 From: hyerijung Date: Fri, 24 Apr 2026 21:57:06 +0900 Subject: [PATCH 3/6] longest-repeating-character-replacement solution --- .../hyeri0903.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 longest-repeating-character-replacement/hyeri0903.java diff --git a/longest-repeating-character-replacement/hyeri0903.java b/longest-repeating-character-replacement/hyeri0903.java new file mode 100644 index 0000000000..d85906bcfc --- /dev/null +++ b/longest-repeating-character-replacement/hyeri0903.java @@ -0,0 +1,39 @@ +class Solution { + public int characterReplacement(String s, int k) { + /** + 1.problem: k번 특정 문자를 골라서 바꿀 수 있다. 이때 same letter 로 이루어진 가장 긴 substring 의 길이을 구하라. + 2.constraints + - s.length min = 1, max = 10^5 + - k.length min = 0, max = s.length + 3.solution + - sliding window: time O(n), space O(1) + */ + + int[] table = new int[26]; + int n = s.length(); + int maxFreq = 0; + int maxLen = 0; + int left = 0; + + for(int right = 0; right < n; right++) { + //1.right 확장 -> count 증가 + int currentChar = s.charAt(right) - 'A'; + table[currentChar]++; + + //2.maxFreq update + maxFreq = Math.max(maxFreq, table[currentChar]); + + //3.조건 깨지면 left 이동하면서 count-- + //바꿔야하는 문자 개수가 k 보다 큰 경우 + if((right - left + 1 - maxFreq) > k) { + int idx = s.charAt(left) - 'A'; + table[idx]--; + left++; + } + + //4.maxLen update + maxLen = Math.max(maxLen, right - left + 1); + } + return maxLen; + } +} From 2a3f7c8cfb6d74ec547a46163cc2d1ea2a89f943 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Fri, 24 Apr 2026 22:07:39 +0900 Subject: [PATCH 4/6] reverse-bits solution --- reverse-bits/hyeri0903.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 reverse-bits/hyeri0903.java diff --git a/reverse-bits/hyeri0903.java b/reverse-bits/hyeri0903.java new file mode 100644 index 0000000000..9512e0d885 --- /dev/null +++ b/reverse-bits/hyeri0903.java @@ -0,0 +1,11 @@ +class Solution { + public int reverseBits(int n) { + int result = 0; + for(int i = 0; i < 32; i++) { + result <<= 1; //왼쪽 이동 + result |= (n & 1); //마지막 비트 붙이기 + n >>= 1; // 오른쪽 이동 + } + return result; + } +} From 5cf072be417dbbe0d7837f8f3a8eddb1f7546d64 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Fri, 24 Apr 2026 22:31:43 +0900 Subject: [PATCH 5/6] palindromic-substrings solution --- palindromic-substrings/hyeri0903.java | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/palindromic-substrings/hyeri0903.java b/palindromic-substrings/hyeri0903.java index e69de29bb2..e7a19f8df3 100644 --- a/palindromic-substrings/hyeri0903.java +++ b/palindromic-substrings/hyeri0903.java @@ -0,0 +1,38 @@ +class Solution { + public int countSubstrings(String s) { + /** + 1.문제: s 에서 palindromoic substring 개수 return + 2.constraints: + - 연속적인 문자 + - s.length min = 1, max = 1000 + 3.풀이 + - bruteforce: time:O(n^3), space:O(n) + - expand around : time(On^2), space:O(1) + */ + + int n = s.length(); + if(n == 1) return 1; + int count = 0; + + for(int i = 0; i < n; i++) { + //odd + count += checkPalindrome(s, i, i); + + //even + count += checkPalindrome(s, i, i+1); + } + return count; + + } + + private int checkPalindrome(String s, int left, int right) { + int count = 0; + while(left >= 0 && right < s.length() && s.charAt(right) == s.charAt(left)) { + count += 1; + left -= 1; + right += 1; + } + return count; + } + +} From ccd1c10f4ebd2c073851a46930e575edce414dc3 Mon Sep 17 00:00:00 2001 From: hyerijung Date: Fri, 24 Apr 2026 22:40:05 +0900 Subject: [PATCH 6/6] clone-graph solution --- clone-graph/hyeri0903.java | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 clone-graph/hyeri0903.java diff --git a/clone-graph/hyeri0903.java b/clone-graph/hyeri0903.java new file mode 100644 index 0000000000..a09359d187 --- /dev/null +++ b/clone-graph/hyeri0903.java @@ -0,0 +1,44 @@ +/* +// Definition for a Node. +class Node { + public int val; + public List neighbors; + public Node() { + val = 0; + neighbors = new ArrayList(); + } + public Node(int _val) { + val = _val; + neighbors = new ArrayList(); + } + public Node(int _val, ArrayList _neighbors) { + val = _val; + neighbors = _neighbors; + } +} +*/ + +class Solution { + //key: original node, value: clone node + private Map map = new HashMap<>(); + + public Node cloneGraph(Node node) { + if(node == null) { + return null; + } + //이미 존재하면 return + if(map.containsKey(node)) { + return map.get(node); + } + + //현재 노드 복제 + Node clone = new Node(node.val); + map.put(node, clone); + + //이웃 노드들 복제해서 연결 + for(Node neighbor: node.neighbors) { + clone.neighbors.add(cloneGraph(neighbor)); + } + return clone; + } +}