From 2bbe41d69902744781e9ab3a576c41c06831866f Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 20 Oct 2026 22:36:19 +0900 Subject: [PATCH 1/2] Create 4078. Three Fibonacci Sum.py --- .../4078. Three Fibonacci Sum.py" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/4078. Three Fibonacci Sum.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/4078. Three Fibonacci Sum.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/4078. Three Fibonacci Sum.py" new file mode 100644 index 00000000..6331d34e --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/4078. Three Fibonacci Sum.py" @@ -0,0 +1,28 @@ +# + +''' +1. 아이디어 : +fibonacci를 n보다 커질때까지 리스트를 만들고, +리스트를 순회하며 3개씩 합친다. + +2. 시간복잡도 : + O(n + n) + +3. 자료구조/알고리즘 : +- + +''' +class Solution: + def threeFibonacciSum(self, n: int) -> bool: + nums = [0, 1] + while nums[-1] <= n: + nums.append(nums[-2] + nums[-1]) + print(nums) + + if len(nums) < 3: + return False + + for i in range(len(nums)-2): + if nums[i] + nums[i+1] + nums[i+2] == n: + return True + return False From 690624ac6002513c46a0bd93e3949f35468f2ee7 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 20 Oct 2026 22:37:26 +0900 Subject: [PATCH 2/2] Create 1130. Minimum Cost Tree From Leaf Values.py --- ...30. Minimum Cost Tree From Leaf Values.py" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1130. Minimum Cost Tree From Leaf Values.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1130. Minimum Cost Tree From Leaf Values.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1130. Minimum Cost Tree From Leaf Values.py" new file mode 100644 index 00000000..6cd5c307 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1130. Minimum Cost Tree From Leaf Values.py" @@ -0,0 +1,46 @@ +# + +''' +1. 아이디어 : +가장 작은 숫자를 찾고, 왼쪽과 오른쪽 중 작은 숫자와 곱하여 ans에 더합니다. 그리고 작은 숫자를 제외한 리스트를 생성 + +2. 시간복잡도 : + O(n * n) + +3. 자료구조/알고리즘 : +그리디 + +''' +class Solution: + def mctFromLeafValues(self, arr: list[int]) -> int: + ans = 0 + + def get_smallest(nums): + n = len(nums) + smallest = float('inf') + index = -1 + + for i, num in enumerate(nums): + if num < smallest: + smallest = num + index = i + + new_nums = [] + for i in range(n): + if i == index: + continue + new_nums.append(nums[i]) + + if index == 0: + product = nums[0] * nums[1] + elif index == n-1: + product = nums[-1] * nums[-2] + else: + product = nums[index] * min(nums[index-1], nums[index+1]) + + return new_nums, product + + while len(arr) > 1: + arr, product = get_smallest(arr) + ans += product + return ans