From d11e8a07e5c3311a4c8447d351c9c6780e2d78bf Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Wed, 2 Dec 2026 23:56:26 +0900 Subject: [PATCH 1/3] Create 1487. Making File Names Unique.py --- .../1487. Making File Names Unique.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1487. Making File Names Unique.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1487. Making File Names Unique.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1487. Making File Names Unique.py" new file mode 100644 index 00000000..2e29ea6a --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1487. Making File Names Unique.py" @@ -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 From 704a4c73240dd2b67fa5057edc3a72c8b0311054 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 3 Dec 2026 22:43:52 +0900 Subject: [PATCH 2/3] Create 1878. Get Biggest Three Rhombus Sums in a Grid.py --- ...t Biggest Three Rhombus Sums in a Grid.py" | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1878. Get Biggest Three Rhombus Sums in a Grid.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1878. Get Biggest Three Rhombus Sums in a Grid.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1878. Get Biggest Three Rhombus Sums in a Grid.py" new file mode 100644 index 00000000..b8e6e927 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1878. Get Biggest Three Rhombus Sums in a Grid.py" @@ -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) From 35f6c8b433c0b20b7d091890ccaba3bef7dcfcc7 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 3 Dec 2026 22:44:03 +0900 Subject: [PATCH 3/3] Create 1711. Count Good Meals.py --- .../1711. Count Good Meals.py" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1711. Count Good Meals.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1711. Count Good Meals.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1711. Count Good Meals.py" new file mode 100644 index 00000000..bc51f02f --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1711. Count Good Meals.py" @@ -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