We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 64ec7d7 commit c67fc15Copy full SHA for c67fc15
1 file changed
second_max_of_array.py
@@ -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