From 3110898e1b64cfb9b44d72e30285e82b54f436ad Mon Sep 17 00:00:00 2001 From: jihyup-byun Date: Mon, 26 Oct 2026 12:48:35 +0000 Subject: [PATCH] 4074 --- .... Maximum Product Pair With Target Sum.py" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/4074. Maximum Product Pair With Target Sum.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4074. Maximum Product Pair With Target Sum.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4074. Maximum Product Pair With Target Sum.py" new file mode 100644 index 00000000..99a0d161 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/4074. Maximum Product Pair With Target Sum.py" @@ -0,0 +1,31 @@ +''' +1. 아이디어 : +- 모든 (i, j) 쌍을 완전탐색하면서 nums[i] + nums[j] == target 이고 nums[i] > nums[j] 인 쌍만 본다. +- 그중 nums[i] * nums[j] 가 최대가 되는 쌍을 갱신하고, 반환은 큰 값의 인덱스가 앞에 오도록 [i, j] 순서를 맞춘다. +- 유효한 쌍이 하나도 없으면 초기값 그대로 [-1, -1] 이 반환된다. +2. 시간복잡도 : +O(n^2) +3. 자료구조/알고리즘 : +- 완전탐색(Brute Force) + +''' + +class Solution: + def maxProductPair(self, nums: list[int], target: int) -> list[int]: + n = len(nums) + mul = -99999 + it = -1 + jt = -1 + for j in range(n-1): + for i in range(j+1,n): + if nums[i] + nums[j] == target and not nums[i] == nums[j]: + if nums[i] * nums[j] > mul: + mul = nums[i] * nums[j] + if nums[i] > nums[j]: + it = i + jt = j + else: + it = j + jt = i + + return [it,jt]