https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
1
2
3
4
5
6
7
8
9
|
from itertools import combinations
class Solution:
def minimumCost(self, nums: List[int]) -> int:
answer = 99999
com = combinations(nums[1:], 2)
for case in com:
answer = min(sum(case), answer)
answer += nums[0]
return answer
|
cs |
0번째 인덱스 값은 무조건 고정이므로 나머지 위치에서 2개씩 뽑아서 그 인덱스 들이 subarray의 각각의 시작점이라고
유도해서 구함
반응형
'python-algorithm' 카테고리의 다른 글
백준 9063 대지 (0) | 2024.01.24 |
---|---|
leetcode 3014. Minimum Number of Pushes to Type Word I (1) | 2024.01.23 |
leetcode 645. Set Mismatch (0) | 2024.01.22 |
leetcode 1207. Unique Number of Occurrences (0) | 2024.01.17 |
leetcode 2913. Subarrays Distinct Element Sum of Squares I (0) | 2024.01.15 |
댓글