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
24 changes: 24 additions & 0 deletions leetcode3/최원준/1487. Making File Names Unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution:
def getFolderNames(self, names: list[str]) -> list[str]:
next_name = {}
ans = []

for name in names:
if name not in next_name:
next_name[name] = 1
ans.append(name)
continue

k = next_name[name]

while f"{name}({k})" in next_name:
k += 1

folder_name = f"{name}({k})"

next_name[name] = k + 1
next_name[folder_name] = 1

ans.append(folder_name)

return ans
33 changes: 33 additions & 0 deletions leetcode3/최원준/1711. Count Good Meals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#

'''
1. 아이디어 :
i번쨰 숫자를 방문할때마다 nums 딕셔너리에 카운트를 한다.
i번째 숫자는, 2의 제곱수들의 나머지가 nums 딕셔너리에 존재하는 만큼 ans에 더한다.

2. 시간복잡도 :
O(n * 22)

3. 자료구조/알고리즘 :
hashmap

'''
class Solution:
def countPairs(self, deliciousness: list[int]) -> int:
MOD = 1_000_000_007
good_meals = set()
nums = defaultdict(int)

delicious_value = 1
while delicious_value <= 2**21:
good_meals.add(delicious_value)
delicious_value *= 2

ans = 0

for delicious in deliciousness:
for target in good_meals:
remain = target - delicious
ans += nums.get(remain, 0)
nums[delicious] += 1
return ans % MOD
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#

'''
1. 아이디어 :
모든 grid를 순회하고, grid마다 radius를 증가시키면서 꼭지점 4개를 만들고 계산합니다.

2. 시간복잡도 :
O(n*n*n*n)

3. 자료구조/알고리즘 :
최소힙, 해시

'''
class Solution:
def getBiggestThree(self, grid: list[list[int]]) -> list[int]:
n = len(grid)
m = len(grid[0])

min_heap = []
visited = set()

def get_corner_sum(corner):
return grid[corner[0]][corner[1]]

def get_side_sum(s, e):
x1, y1 = s
x2, y2 = e

x_dir = 1 if x2 >= x1 else -1
y_dir = 1 if y2 >= y1 else -1

total = grid[x1][y1]

x, y = x1, y1

while x != x2 and y != y2:
x += x_dir
y += y_dir
total += grid[x][y]

return total

def get_sums(x, y, radius):
if radius == 0:
return grid[x][y]

p1 = [x-radius, y] # 12시
p2 = [x, y+radius] # 3시
p3 = [x+radius, y] # 6시
p4 = [x, y-radius] # 9시

if (x-radius < 0 or x+radius >= n
or y-radius < 0 or y+radius >= m):
return -1

total = 0
total += get_side_sum(p1, p2)
total += get_side_sum(p2, p3)
total += get_side_sum(p3, p4)
total += get_side_sum(p4, p1)

total -= (
get_corner_sum(p1)
+ get_corner_sum(p2)
+ get_corner_sum(p3)
+ get_corner_sum(p4)
)

return total

for row in range(n):
for col in range(m):
for radius in range(min(n, m)):
total = get_sums(row, col, radius)

if total == -1:
break

if total in visited:
continue

visited.add(total)
heapq.heappush(min_heap, total)

if len(min_heap) > 3:
removed = heapq.heappop(min_heap)
visited.remove(removed)

return sorted(min_heap, reverse=True)