Skip to content

Commit 54ae8af

Browse files
authored
Create maximum_and_minimum.py
1 parent c8f5c29 commit 54ae8af

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

maximum_and_minimum.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
"""
3+
@param matrix: an input matrix
4+
@return: nums[0]: the maximum,nums[1]: the minimum
5+
"""
6+
def maxAndMin(self, matrix):
7+
# write your code here
8+
if not matrix:
9+
return []
10+
r = [matrix[0][0], matrix[0][0]]
11+
for row in matrix:
12+
for i in row:
13+
if i > r[0]: # 确保max在前min在后
14+
r[0] = i
15+
elif i < r[1]:
16+
r[1] = i
17+
return r
18+
19+
# easy: https://www.lintcode.com/problem/maximum-and-minimum

0 commit comments

Comments
 (0)