11---
22title : 2679.In the matrix and the harmony.md
3- date : ' 2024.01.01 0:00'
3+ date : " 2024.01.01 0:00"
44tags :
55 - - Python
66 - - answer
99 - - Sort
1010 - - simulation
1111 - - heap(Priority queue)
12- abbrlink : ' 5277100'
12+ abbrlink : " 5277100"
13+ docId : clx9mmqqvxipdfamqciuo146
1314---
1415
1516# topic:
1617
1718[ 2679.In the matrix and the harmony.md] ( https://leetcode.cn/problems/sum-in-a-matrix/ )
1819
1920# Thought:
21+
2022** One -line**
2123First of all, the meaning is to find the largest number of each sub -list,Thenpopgo out,Finally ask for peace。
2224The effect of traversing again and again is too bad,So I thought of using itzip一次性Traversal多个子Array。
@@ -31,6 +33,7 @@ Find the maximum:
3133` [3,5,7] `
3234Context:
3335` 15 `
36+
3437# Code:
3538
3639``` python
@@ -39,8 +42,10 @@ class Solution:
3942 return sum (max (i) for i in \
4043 zip (* (sorted (sublist) for sublist in nums)))
4144```
42- ### * The role and the rolezip()explain
43- ``` python
45+
46+ ### \* The role and the rolezip()explain
47+
48+ ``` python
4449nums = [[1 ,2 ,7 ],[2 ,4 ,6 ],[3 ,5 ,6 ],[1 ,2 ,3 ]]
4550
4651for i in range (len (nums[1 ])):
@@ -52,28 +57,34 @@ num2 = [2,4,6]
5257num3 = [3 ,5 ,6 ]
5358num4 = [1 ,2 ,3 ]
5459```
60+
5561` zip() ` The function corresponds to one -to -one elements in multiple lists,Then return onezipObject,Can uselist()Function convert to list。
62+
5663``` python
5764for i in zip (num1, num2, num3, num4):
5865 print (i)
5966# (1, 2, 3, 1)
6067# (2, 4, 5, 2)
6168# (7, 6, 6, 3)
6269```
70+
6371` *nums ` The role ispythonNot a pointer,InsteadnumsEach element in the parameter is passed into the function。I understand here as a list。
72+
6473``` python
6574
6675# Enumerate
6776print (* nums)
6877# [1, 2, 7] [2, 4, 6] [3, 5, 6] [1, 2, 3]
6978```
79+
7080` zip(*nums) ` WillnumsEach element is passed in as a parameterzip()In the function,Then return onezipObject,Can uselist()Function convert to list。
7181` zip(*nums) ` Equivalent to` zip(num1, num2, num3, num4) ` ,innum1, num2, num3, num4yesnumsElement。
82+
7283``` python
7384for i in zip (* nums):
7485 print (i)
7586# Equivalent
7687# (1, 2, 3, 1)
7788# (2, 4, 5, 2)
7889# (7, 6, 6, 3)
79- ```
90+ ```
0 commit comments