diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" new file mode 100644 index 00000000..ae89c40e --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" @@ -0,0 +1,53 @@ +# + +''' +1. 아이디어 : +- index 값이 1씩 오를때 얼마나 오르는지 O(1)로 계산해야한다. +왼쪽, 오른쪽 등차 계산: (첫 숫자 + 마지막 숫자) x 갯수 / 2 +계산하는 거리가 실제 존재하는 숫자보다 많은 경우 등차 계산으로는 초과하는 숫자들까지 포함되어서 else로 분기. +- 거리를 1씩 올리게 되면 (n)이고 시간초과. 이분탐색으로 logn으로 찾는다 + +2. 시간복잡도 : + O(logn) + +3. 자료구조/알고리즘 : +이분탐색 + +''' +class Solution: + def maxValue(self, n: int, index: int, maxSum: int) -> int: + + + left_nums = index + right_nums = n-index-1 + + def get_total(distance, count): + if distance > count: + exceed = distance - count + return distance * (distance - 1) // 2 - exceed * (exceed - 1) // 2 + else: + return distance * (distance - 1) // 2 + (count - distance + 1) + + def calculate_total(distance): + left_total = get_total(distance, left_nums) + right_total = get_total(distance, right_nums) + return left_total + distance + right_total + + + ans = 0 + + left = 1 + right = maxSum + 1 + + while left <= right: + mid = (left + right) // 2 + + if calculate_total(mid) <= maxSum: + ans = mid + left = mid + 1 + else: + right = mid - 1 + + return ans + + diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1828. Queries on Number of Points Inside a Circle.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1828. Queries on Number of Points Inside a Circle.py" new file mode 100644 index 00000000..e4d203f9 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1828. Queries on Number of Points Inside a Circle.py" @@ -0,0 +1,28 @@ +# + +''' +1. 아이디어 : +완전 탐색으로 쿼리마다 점들의 거리를 계산한다. + +2. 시간복잡도 : + O(n * m) + +3. 자료구조/알고리즘 : +- + +''' +class Solution: + def countPoints(self, points: list[list[int]], queries: list[list[int]]) -> list[int]: + + def get_distance(x1, y1, x2, y2): + return (abs(x1-x2) ** 2 + abs(y1-y2) ** 2) ** (1/2) + + ans = [] + + for x1, y1, r in queries: + count = 0 + for x2, y2 in points: + if get_distance(x1, y1, x2, y2) <= r: + count += 1 + ans.append(count) + return ans