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
48 changes: 48 additions & 0 deletions clone-graph/Hyeri1ee.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) 방식으로 방문하며 복제하는 방식으로 구현되어 있습니다. 재귀 호출을 통해 인접 노드를 순차적으로 탐색하는 구조입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.util.*;
/*
class Node {
public int val;
public List<Node> neighbors;
public Node() {
val = 0;
neighbors = new ArrayList<Node>();
}
public Node(int _val) {
val = _val;
neighbors = new ArrayList<Node>();
}
public Node(int _val, ArrayList<Node> _neighbors) {
val = _val;
neighbors = _neighbors;
}
}
*/


class Solution {


//기존 node, 복사한 node
Map<Node, Node> visited = new HashMap<>();
public Node cloneGraph(Node node) {
if (node==null) return null;

if (visited.containsKey(node)){
return visited.get(node);
}

//없는 경우
Node newClone= new Node(node.val);
visited.put(node, newClone);

//이웃 복사
for(Node target : node.neighbors){
newClone.neighbors.add(cloneGraph(target));
}

return newClone;

}
}


33 changes: 33 additions & 0 deletions longest-common-subsequence/Hyeri1ee.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
  • 설명: 이 코드는 두 문자열의 최장 공통 부분 수열을 찾기 위해 DP 테이블을 활용하여 이전 결과를 저장하며 최적 해를 구하는 방식입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.*;
class Solution {
public int longestCommonSubsequence(String text1, String text2) {


//int longerlen= (text1.length() >= text2.length()) ? text1.length() : text2.length();
//int lesslen= (text1.length() <= text2.length()) ? text1.length() : text2.length();
int[][] dp = new int[text1.length()+1][text2.length()+1];

//String longertext= (text1.length() >= text2.length()) ? text1 : text2;
//String lesstext= (text1.length() <= text2.length()) ? text1 : text2;



for (int i = 1; i <=text1.length(); i++) {
for (int j = 1; j <=text2.length(); j++) {
//문자가 같으면
if (text1.charAt(i-1) == text2.charAt(j-1)){
dp[i][j] = dp[i-1][j-1]+1;
//System.out.println("dp["+i+"]["+j+"]: "+ dp[i][j]);
}else{
//문자가 다르면
dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
//System.out.println("dp["+i+"]["+j+"]: "+ dp[i][j]);
}
}
}


return dp[text1.length()][text2.length()];
}//end of method
}

61 changes: 61 additions & 0 deletions longest-repeating-character-replacement/Hyeri1ee.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
  • 설명: 이 코드는 슬라이딩 윈도우 기법으로 연속된 문자열 구간을 탐색하며, 문자 빈도수 저장을 위해 해시 맵(배열)을 활용합니다. 윈도우 크기 조절과 빈도수 갱신으로 최적 해를 찾는 패턴입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class Solution {
//left,right

//right를 left에서부터 이동하면서 max (대체해야되는 alphabet 수) 갱신
//(right - left+ 1) - 다수등장alphabet 개수 = 대체해야되는 alphabet 수
//대체해야되는 수 <= k 인 경우 완료
//"" > k 인 경우 left++

//빈도수 저장용
int[] alpha = new int[26];
int answer =0 ;

public int characterReplacement(String s, int k) {

//인덱스 정의 (초기값)
int left= 0;
int right= 0;



while(right < s.length()){
//현재 갱신된 right까지 빈도수 저장
//System.out.println("[right] : " + right);
//System.out.println("[left] : " + left);

alpha[s.charAt(right) - 'A']++;

int max = mostSeenFrequency(left, right, alpha);



while ((right-left + 1) - max > k) {
alpha[s.charAt(left) - 'A']--;
left++;
max = mostSeenFrequency(left, right, alpha);
}

if (answer < right-left + 1){
answer=right-left+1;
}
right++;

//System.out.println("[answer] : " + answer);


}//end of while

return answer;

}

private static int mostSeenFrequency(int left, int right, int[] alpha){
int max =0;
for(int i=0;i<26;i++){
if (max < alpha[i]) max=alpha[i];
}
return max;
}
}


49 changes: 49 additions & 0 deletions palindromic-substrings/Hyeri1ee.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers
  • 설명: 이 코드는 문자열의 부분 문자열을 양 끝에서부터 비교하는 방식으로 팰린드롬 여부를 판단하여, 두 포인터를 활용하는 Two Pointers 패턴에 속합니다. 이를 통해 효율적으로 팰린드롬 검사를 수행합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Solution {
//길이 1~s.length()까지 palindrome 함수 시도
int cnt=0; //


public int countSubstrings(String s) {

for(int len=1; len <= s.length();len++){//1~3
for(int idx =0; idx <= s.length()-len ; idx++){
//idx인덱스부터 len길이만큼의 문자열이 palindrome인지 판별
boolean result = isPalindrome(s, idx, idx+len-1); //start: 시작 인덱스 , end: 끝 인덱스

if (result){
cnt++;
}
}
}

return cnt;

}

private static boolean isPalindrome(String w, int start, int end){
if (start == end) return true;
//start!= end
int s = start;
int e = end;
while(s<= e){
if(e < start && s > end) return true;


//서로 값이 다른 경우
if (w.charAt(s) != w.charAt(e)){
return false;
}

//서로 값이 같은 경우 continue;
s++;
e--;
}


return true;
}


}


13 changes: 13 additions & 0 deletions reverse-bits/Hyeri1ee.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
  • 설명: 이 코드는 비트 연산자를 활용하여 정수의 비트 순서를 뒤집는 방식으로, 비트 조작을 통해 문제를 해결하는 패턴입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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;
}
}

Loading