Skip to content

Commit c67fc15

Browse files
authored
Create second_max_of_array.py
1 parent 64ec7d7 commit c67fc15

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

second_max_of_array.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
"""
3+
@param nums: An integer array
4+
@return: The second max number in the array.
5+
"""
6+
@staticmethod
7+
def update(data, value):
8+
m = min(data)
9+
if data[0] == m:
10+
pos = 0
11+
else:
12+
pos = 1
13+
if value > data[pos]:
14+
data[pos] = value # 更新比较小的那个数
15+
16+
def secondMax(self, nums):
17+
# write your code here
18+
data = nums[0:2]
19+
for i in range(2, len(nums)):
20+
Solution.update(data, nums[i])
21+
return min(data)
22+
23+
# easy: https://www.lintcode.com/problem/second-max-of-array

0 commit comments

Comments
 (0)