diff --git "a/minjeong/HashMap/2025-07-02-[PGS]-\354\231\204\354\243\274\355\225\230\354\247\200\353\252\273\355\225\234\354\204\240\354\210\230(java).java" "b/minjeong/HashMap/2025-07-02-[PGS]-\354\231\204\354\243\274\355\225\230\354\247\200\353\252\273\355\225\234\354\204\240\354\210\230(java).java" new file mode 100644 index 00000000..89ead728 --- /dev/null +++ "b/minjeong/HashMap/2025-07-02-[PGS]-\354\231\204\354\243\274\355\225\230\354\247\200\353\252\273\355\225\234\354\204\240\354\210\230(java).java" @@ -0,0 +1,39 @@ +// 풀이 1: 정렬을 이용한 풀이 +import java.util.*; + +class Solution { + public String solution(String[] participant, String[] completion) { + Arrays.sort(participant); + Arrays.sort(completion); + + for (int i = 0; i < completion.length; i++) { + if (!participant[i].equals(completion[i])) { + return participant[i]; + } + } + + return participant[participant.length - 1]; + } +} + +// 풀이2: 해시맵을 이용한 풀이 +import java.util.*; + +class Solution { + public String solution(String[] participant, String[] completion) { + String answer = ""; + + HashMap dict = new HashMap<>(); + + for (String p : participant) dict.put(p, dict.getOrDefault(p, 0) + 1); + for (String c : completion) dict.put(c, dict.get(c) - 1); + + for (String key: dict.keySet()) { + if (dict.get(key) != 0) { + answer = key; + } + } + + return answer; + } +} \ No newline at end of file diff --git "a/minjeong/Simulation/2025-07-05-[PGS]-\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.py" "b/minjeong/Simulation/2025-07-05-[PGS]-\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.py" new file mode 100644 index 00000000..e7d671eb --- /dev/null +++ "b/minjeong/Simulation/2025-07-05-[PGS]-\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.py" @@ -0,0 +1,63 @@ +def check_remove(m, n, grid): + """ + 2×2 같은 블록을 찾아서, 지울 칸을 True로 표시한 2D 배열을 반환한다. + """ + mark = [[False] * n for _ in range(m)] + for i in range(m-1): + for j in range(n-1): + current = grid[i][j] + if current and grid[i][j+1] == current \ + and grid[i+1][j] == current \ + and grid[i+1][j+1] == current: + mark[i][j] = mark[i][j+1] = mark[i+1][j] = mark[i+1][j+1] = True + return mark + +def remove_blocks(m, n, grid, mark): + """ + mark 배열이 True인 칸으르 찾아서 빈칸으로 바꾸고, + 삭제된 블록의 총 개수를 반환한다. + """ + removed = 0 + for i in range(m): + for j in range(n): + if mark[i][j]: + grid[i][j] = "" + removed += 1 + return removed + +def down_blocks(m, n, grid): + """ + 중력을 적용하여, 각 열마다 빈칸 위의 블록을 아래로 당긴다. + """ + for j in range(n): + stack = [] + for i in range(m): + if grid[i][j] != "": + stack.append(grid[i][j]) + + for i in range(m-1, -1, -1): + if stack: + grid[i][j] = stack.pop() + + else: + grid[i][j] = "" + +def solution(m, n, board): + # 1. 입력 문자열을 2D 리스트로 변환 + grid = [list(row) for row in board] + total_removed = 0 + + while True: + # 2. 지울 칸 표시 + mark = check_remove(m, n, grid) + # 3. 표시된 칸 삭제 및 개수 세기 + removed = remove_blocks(m, n, grid, mark) + if removed == 0: + # 더이상 지울 블록이 없다면 반복 종료 + break + # 4. 전체 삭제 개수에 해당 칸의 삭제 개수 누적해서 더하기 + total_removed += removed + # 5. 중력 적용 + down_blocks(m, n, grid) + + return total_removed diff --git "a/minjeong/Stack, Queue, Priority Queue/2025-07-05-[PGS]-\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" "b/minjeong/Stack, Queue, Priority Queue/2025-07-05-[PGS]-\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" new file mode 100644 index 00000000..46f74d84 --- /dev/null +++ "b/minjeong/Stack, Queue, Priority Queue/2025-07-05-[PGS]-\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220.py" @@ -0,0 +1,64 @@ +import heapq + + +def solution(operations): + min_heap = [] + max_heap = [] + number_count = {} # 각 숫자가 큐에 몇 번 남았는지 카운트 + size = 0 # 현재 큐에 남아있는 총 원소 수 + + for op in operations: + cmd, num_str = op.split(' ') + num = int(num_str) + + if cmd == 'I': + # 삽입 + heapq.heappush(min_heap, num) + heapq.heappush(max_heap, -num) + number_count[num] = number_count.get(num, 0) + 1 + size += 1 + else: # cmd == 'D' + if size == 0: + # 큐가 비어있다면 연산 무시 + continue + + if num == 1: + # 최댓값 삭제 + while max_heap: + x = -heapq.heappop(max_heap) + if number_count.get(x, 0) > 0: + # num이 1번 이상 등장했다면, 카운트 반영 + number_count[x] -= 1 + size -= 1 + break + else: + # num == -1, 최솟값 삭제 + while min_heap: + x = heapq.heappop(min_heap) + if number_count.get(x, 0) > 0: + # num이 1번 이상 등장했다면, 카운트 반영 + number_count[x] -= 1 + size -= 1 + break + + # 연산 후 큐가 비어있다면 [0, 0] + if size == 0: + return [0, 0] + + # 남아있는 최댓값 찾기 + max_value = 0 + while max_heap: + x = -heapq.heappop(max_heap) + if number_count.get(x, 0) > 0: + max_value = x + break + + # 남아있는 최솟값 찾기 + min_value = 0 + while min_heap: + x = heapq.heappop(min_heap) + if number_count.get(x, 0) > 0: + min_value = x + break + + return [max_value, min_value] \ No newline at end of file diff --git "a/minjeong/TwoPointer_SlidingWindow/2025-06-24-[PGS]-\352\265\254\353\252\205\353\263\264\355\212\270(java).java" "b/minjeong/TwoPointer_SlidingWindow/2025-06-24-[PGS]-\352\265\254\353\252\205\353\263\264\355\212\270(java).java" new file mode 100644 index 00000000..856400da --- /dev/null +++ "b/minjeong/TwoPointer_SlidingWindow/2025-06-24-[PGS]-\352\265\254\353\252\205\353\263\264\355\212\270(java).java" @@ -0,0 +1,23 @@ +import java.util.*; + +class Solution { + public int solution(int[] people, int limit) { + int boat = 0; + int left = 0; + int right = people.length - 1; + + Arrays.sort(people); + + while (left <= right) { + if (people[left] + people[right] <= limit) { + left += 1; + right -= 1; + } else { + right -= 1; + } + boat += 1; + + } + return boat; + } +} \ No newline at end of file