diff --git "a/leetcode2/1easy/\354\265\234\354\233\220\354\244\200/Q2511.java" "b/leetcode2/1easy/\354\265\234\354\233\220\354\244\200/Q2511.java" new file mode 100644 index 00000000..74b444ae --- /dev/null +++ "b/leetcode2/1easy/\354\265\234\354\233\220\354\244\200/Q2511.java" @@ -0,0 +1,64 @@ +package Leetcode.최원준; + +/* +1. 아이디어 : + + +2. 시간복잡도 : +O( ) + +3. 자료구조/알고리즘 : + + */ + +public class Q2511 { + class Solution { + public int captureForts(int[] forts) { + int n = forts.length; + + int ans = 0; + int curr = -n; + boolean found = false; + for (int i=0; i-1; i--) { + if (forts[i] == 1) { + found = true; + curr = 0; + } + + if (forts[i] == 0 && found) { + curr++; + } + + if (forts[i] == -1) { + if (found) { + ans = Math.max(ans, curr); + } + curr = 0; + found = false; + } + } + return ans; + } + } +} diff --git "a/leetcode2/2medium/\354\265\234\354\233\220\354\244\200/Q3310.java" "b/leetcode2/2medium/\354\265\234\354\233\220\354\244\200/Q3310.java" new file mode 100644 index 00000000..cd94abc0 --- /dev/null +++ "b/leetcode2/2medium/\354\265\234\354\233\220\354\244\200/Q3310.java" @@ -0,0 +1,80 @@ +package Leetcode.최원준; + +/* +1. 아이디어 : + + +2. 시간복잡도 : +O( ) + +3. 자료구조/알고리즘 : + + */ + +import java.util.*; + +public class Q3310 { + class Solution { + int[] par; + + public List remainingMethods(int n, int k, int[][] invocations) { + par = new int[n]; + for (int i=0; i> invokes = new HashMap<>(); + for (int[] i : invocations) { + invokes.putIfAbsent(i[0], new ArrayList<>()); + invokes.get(i[0]).add(i[1]); + } + + Deque deque = new ArrayDeque<>(); + boolean[] visited = new boolean[n]; + visited[k] = true; + deque.add(k); + + while (!deque.isEmpty()) { + int curr = deque.pollFirst(); + + for (int neighbor : invokes.getOrDefault(curr, new ArrayList<>())) { + if (visited[neighbor]) continue; + visited[neighbor] = true; + deque.add(neighbor); + union(curr, neighbor); + } + } + + for (int i=0; i())) { + int rootNeighbor = find(neighbor); + visited[rootNeighbor] = false; + } + } + + List ans = new ArrayList<>(); + for (int i=0; i rb) { + par[rb] = ra; + } else { + par[ra] = rb; + } + return false; + } + } +}