# 1167. Minimum Cost to Connect Sticks

{% embed url="<https://leetcode.com/problems/minimum-cost-to-connect-sticks/>" %}

其实根本就不是DP吧，一开始用DP的方法写，一直TLE，改成heap直接一直取最小就行了。

```python
class Solution:
    def connectSticks(self, sticks: List[int]) -> int:
        if not sticks or len(sticks) <= 1: return 0
        
        heapq.heapify(sticks)
        
        res = 0
        while sticks:
            i = heapq.heappop(sticks)
            if sticks:
                j = heapq.heappop(sticks)
                res += (i+j)
                heapq.heappush(sticks, i+j)
                
        return res
```
