From 7aee3c34a0e893b03da8684a02fa8b3c4bcad586 Mon Sep 17 00:00:00 2001 From: Minjeong Kim Date: Thu, 26 Jun 2025 23:47:21 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[PGS]=20=EA=B5=AC=EB=AA=85=EB=B3=B4?= =?UTF-8?q?=ED=8A=B8=20(java)=20/=20Level=202=20/=2010=EB=B6=84=20/=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...52\205\353\263\264\355\212\270(java).java" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "minjeong/TwoPointer_SlidingWindow/2025-06-24-[PGS]-\352\265\254\353\252\205\353\263\264\355\212\270(java).java" 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 0000000..856400d --- /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 From 449a1b32462ff4cbf0921507aaf53f3fc7554171 Mon Sep 17 00:00:00 2001 From: Minjeong Kim Date: Wed, 2 Jul 2025 17:57:16 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[PGS]=20=EC=99=84=EC=A3=BC=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EB=AA=BB=ED=95=9C=20=EC=84=A0=EC=88=98=20(Java)=20?= =?UTF-8?q?/=20Level=201=20/=2015=EB=B6=84=20/=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\234\354\204\240\354\210\230(java).java" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "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" 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 0000000..89ead72 --- /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 From 191396fbe759f2d3f8620c650a267e2c349f830c Mon Sep 17 00:00:00 2001 From: Minjeong Kim Date: Sat, 5 Jul 2025 17:31:49 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[PGS]=20=EC=9D=B4=EC=A4=91=EC=9A=B0?= =?UTF-8?q?=EC=84=A0=EC=88=9C=EC=9C=84=20=ED=81=90=20/=20Level=203=20/=202?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20/=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\354\210\234\354\234\204\355\201\220.py" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "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" 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 0000000..46f74d8 --- /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 From c9eee97dd0a261713ad2a4403fbd1afe0b989741 Mon Sep 17 00:00:00 2001 From: Minjeong Kim Date: Sat, 5 Jul 2025 23:49:27 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[PGS]=20=ED=94=84=EB=A0=8C=EC=A6=884?= =?UTF-8?q?=EB=B8=94=EB=A1=9D=20/=20Level=202=20/=201=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?/=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\246\2104\353\270\224\353\241\235.py" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "minjeong/Simulation/2025-07-05-[PGS]-\355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.py" 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 0000000..b950035 --- /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,45 @@ +def check(m, n, board): + filter = [[0 for _ in range(n)] for _ in range(m)] + count = 0 + + for i in range(m - 1): + for j in range(n - 1): + a = board[i][j] + b = board[i][j + 1] + c = board[i + 1][j] + d = board[i + 1][j + 1] + if a == b == c == d and a != '0': + filter[i][j], filter[i][j + 1], filter[i + 1][j], filter[i + 1][j + 1] = 1, 1, 1, 1 + + for i in range(m): + for j in range(n): + if filter[i][j] == 1: + count += 1 + board[i][j] = '0' + + if count == 0: + return 0 + + for i in range(m - 2, -1, -1): + for j in range(n): + k = i + while 0 <= k + 1 < m and board[k + 1][j] == '0': + k += 1 + if k != i: + board[k][j] = board[i][j] + board[i][j] = '0' + + return count + + +def solution(m, n, board): + answer = 0 + board = list(map(list, board)) + + while True: + temp = check(m, n, board) + if temp == 0: + break + answer += temp + + return answer \ No newline at end of file From d11a0bcc9828cd60fa6a660dcda8fc7092aaba49 Mon Sep 17 00:00:00 2001 From: Minjeong Kim Date: Sun, 6 Jul 2025 10:37:54 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refact:=20=ED=94=84=EB=A0=8C=EC=A6=884?= =?UTF-8?q?=EB=B8=94=EB=A1=9D=20=EB=AC=B8=EC=A0=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\246\2104\353\270\224\353\241\235.py" | 92 +++++++++++-------- 1 file changed, 55 insertions(+), 37 deletions(-) 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" index b950035..e7d671e 100644 --- "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" @@ -1,45 +1,63 @@ -def check(m, n, board): - filter = [[0 for _ in range(n)] for _ in range(m)] - count = 0 - - for i in range(m - 1): - for j in range(n - 1): - a = board[i][j] - b = board[i][j + 1] - c = board[i + 1][j] - d = board[i + 1][j + 1] - if a == b == c == d and a != '0': - filter[i][j], filter[i][j + 1], filter[i + 1][j], filter[i + 1][j + 1] = 1, 1, 1, 1 - +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 filter[i][j] == 1: - count += 1 - board[i][j] = '0' - - if count == 0: - return 0 - - for i in range(m - 2, -1, -1): - for j in range(n): - k = i - while 0 <= k + 1 < m and board[k + 1][j] == '0': - k += 1 - if k != i: - board[k][j] = board[i][j] - board[i][j] = '0' - - return count - + 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): - answer = 0 - board = list(map(list, board)) + # 1. 입력 문자열을 2D 리스트로 변환 + grid = [list(row) for row in board] + total_removed = 0 while True: - temp = check(m, n, board) - if temp == 0: + # 2. 지울 칸 표시 + mark = check_remove(m, n, grid) + # 3. 표시된 칸 삭제 및 개수 세기 + removed = remove_blocks(m, n, grid, mark) + if removed == 0: + # 더이상 지울 블록이 없다면 반복 종료 break - answer += temp + # 4. 전체 삭제 개수에 해당 칸의 삭제 개수 누적해서 더하기 + total_removed += removed + # 5. 중력 적용 + down_blocks(m, n, grid) - return answer \ No newline at end of file + return total_removed