---
# System prepended metadata

title: 2679. Sum in a Matrix
tags: [Leetcode, Simulation, Medium]

---

Link: https://leetcode.com/problems/sum-in-a-matrix/description/
## 思路
python ```zip()```和```zip(*)``` 用法: https://www.jianshu.com/p/ff23ebb8dcc8
先排序每一行 然后把每一列的最大值相加就是答案
## Code
```python=
class Solution:
    def matrixSum(self, nums: List[List[int]]) -> int:
        return sum(max(col) for col in zip(*[sorted(row) for row in nums]))
```
```python=
class Solution:
    def matrixSum(self, nums: List[List[int]]) -> int:
        r, c = len(nums), len(nums[0])
        ans = 0
        for i in range(r):
            nums[i].sort()
        for j in range(c):
            colMax = 0
            for i in range(r):
                colMax = max(colMax, nums[i][j])
            ans += colMax
        return ans
```