python | very simple solution with detailed explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nThe idea behind this solution is that you can swap any 2 numbers in the matrix together
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe idea behind this solution is that you can swap any 2 numbers in the matrix together (doesnt mather if they are adjecent or not, try for yourself). Just swap the number you want to swap together with a neighbor and then swap the neighbor together with another neighbor until you reach the other number you wanted to swap. All the neighbor in between will have been swapped back. \n\nThis means, since we can swap any 2 numbers, we have to only have to choose the best number to swap. This is easy, if the amount of negatives is an even number, you can swap all of them (2 at a time), so just return the sum of all absolute numbers. If the amount of negatives is an odd number, one of the number cannot be swapped. This means we have to choose which number stays or becomes negative, so we obviously choose the smallest number. If this is the case, return the total sum of all absolute numbers and decrease this with smallest number * 2 (since the difference between x and -x is 2x).\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nLoop over all number and count the amount of negatives you encounter, keep track of the smallest (absolute) number you encounter and keep track of the total sum of all absolute numbers. \n\nUpvote if this helped or if you just like the cat\n![image.png](https://assets.leetcode.com/users/images/1282d0bc-7281-4d33-a658-9adb38a2ad34_1732451554.9522705.png)\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```python3 []\nclass Solution:\n    def maxMatrixSum(self, matrix: List[List[int]]) -> int:\n        res = 0\n        negatives = 0\n        smallest = float("inf")\n        for row in matrix:\n            for num in row:\n                if num < 0:\n                    negatives += 1\n                smallest = min(smallest,abs(num))\n                res += abs(num)\n        if negatives % 2 == 0:\n            return res\n        return res - 2*smallest\n        \n        \n```
['Python3']