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

/*
1. 아이디어 :

- 처음 값을 넣고 계속 비교하면서 애나그램이 아닌경우 넣기

2. 시간복잡도 :
O( n log n )
3. 자료구조/알고리즘 :
- / 완전탐색
*/

public class Q2273 {
class Solution {
public List<String> removeAnagrams(String[] words) {
List<String> result = new ArrayList<>();
result.add(words[0]);

for (int i = 1; i < words.length; i++) {
if (!isAnagram(result.get(result.size() - 1), words[i])) {
result.add(words[i]);
}
}

return result;
}

private boolean isAnagram(String s1, String s2) {
char[] a = s1.toCharArray();
char[] b = s2.toCharArray();
Arrays.sort(a);
Arrays.sort(b);
return Arrays.equals(a, b);
}
}
}
55 changes: 55 additions & 0 deletions leetcode2/2medium/Q2368.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package Leetcode;

/*
1. 아이디어 :

- 인접 리스트 생성 후
- bfs로 각 레벨 하나씩 내려가면서 확인

2. 시간복잡도 :
O( n )
3. 자료구조/알고리즘 :
- / bfs
*/

public class Q2368 {
class Solution {
public int reachableNodes(int n, int[][] edges, int[] restricted) {
List<List<Integer>> graph = new ArrayList<>();
for(int i = 0; i<n;i++) graph.add(new ArrayList<>());

for(int[] edge : edges) {
graph.get(edge[0]).add(edge[1]);
graph.get(edge[1]).add(edge[0]);
}

Set<Integer> restrictedSet = new HashSet<>();
for(int r : restricted) {
restrictedSet.add(r);
}

boolean[] visited = new boolean[n];
Queue<Integer> queue = new LinkedList<>();

queue.offer(0);
visited[0] = true;

int count = 0;

while(!queue.isEmpty()) {
int node = queue.poll();
count++;

for(int neighbour : graph.get(node)) {
if(!visited[neighbour] && !restrictedSet.contains(neighbour)) {
visited[neighbour] = true;
queue.offer(neighbour);
}
}
}
return count;
}


}
}