Heap | 8 lines | Clean code | Easy to understand
Intuition\n Describe your first thoughts on how to solve this problem. \nUsing heap to keep track of minimum number on each step\n# Approach\n Describe your app
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUsing heap to keep track of minimum number on each step\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThis is a simple question, don\'t need to think too much\nOn every step, we need to choose the minimum number of array to negate it.\nTo keep track of minimum number, we need to use `heap`\nThat\'s it.\n\n# Complexity\n- Time complexity: O(n*log(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def largestSumAfterKNegations(self, nums: List[int], k: int) -> int:\n        heap = []\n        for n in nums:\n            heapq.heappush(heap, n)\n        while k > 0:\n            minimum = heapq.heappop(heap)\n            heapq.heappush(heap,-minimum)\n            k -= 1\n        return sum(heap)\n```
['Heap (Priority Queue)', 'Python3']