对一列数进行reorder和decrease,使得这列数以1开始,相邻数差别不超过1,问数列里最大值是多少,贪心
1 #1846
2 #Runtime: 359 ms (Beats 100%)
3 #Memory: 21.7 MB (Beats 5.56%)
4
5 class Solution(object):
6 def maximumElementAfterDecrementingAndRearranging(self, arr):
7 """
8 :type arr: List[int]
9 :rtype: int
10 """
11 arr.sort()
12 st = 1
13 for x in arr[1:]:
14 if x > st:
15 st += 1
16 return st