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
Original file line number Diff line number Diff line change
@@ -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<String, Integer> 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;
}
}
63 changes: 63 additions & 0 deletions minjeong/Simulation/2025-07-05-[PGS]-프렌즈4블록.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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;
}
}