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
21 changes: 21 additions & 0 deletions leetcode2/1easy/최원준/Q521.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Leetcode.최원준;

/*
1. 아이디어 :
두 문자열이 같으면 -1을 반환하고, 다르면 두 문자열의 길이 중 큰 값을 반환

2. 시간복잡도 :
O( 1 )

3. 자료구조/알고리즘 :
- / -
*/

public class Q521 {
class Solution {
public int findLUSlength(String a, String b) {
if (a.equals(b)) return -1;
return Math.max(a.length(), b.length());
}
}
}
45 changes: 45 additions & 0 deletions leetcode2/2medium/최원준/Q1218.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package Leetcode.최원준;

/*
1. 아이디어 :
해시맵을 사용하여 각 숫자에 대해 이전 숫자와의 차이가 difference인 경우의 길이를 저장

2. 시간복잡도 :
O( n )

3. 자료구조/알고리즘 :
해시맵 / dp
*/

import java.util.HashMap;
import java.util.Map;

public class Q1218 {
class Solution {
public int longestSubsequence(int[] arr, int difference) {
int n = arr.length;
int ans = 1;
int prev = arr[0];
Map<Integer, Integer> lengths = new HashMap<>();

for (int num : arr) {
if (lengths.containsKey(num - difference)) {
int length = lengths.get(num - difference);
lengths.remove(num-difference);
if (lengths.containsKey(num)) {
lengths.put(num, Math.max(lengths.get(num), length+1));
} else {
lengths.put(num, length+1);
}
} else {
lengths.putIfAbsent(num, 1);
}
}
System.out.println(lengths);
for (int length : lengths.values()) {
ans = Math.max(ans, length);
}
return ans;
}
}
}