1846. 减小和重新排列数组后的最大元素
为保证权益,题目请参考 1846. 减小和重新排列数组后的最大元素(From LeetCode).
解决方案1
Python
python
# 1846. 减小和重新排列数组后的最大元素
# https://leetcode-cn.com/problems/maximum-element-after-decreasing-and-rearranging/
from typing import List
class Solution:
def maximumElementAfterDecrementingAndRearranging(self, arr: List[int]) -> int:
arr.sort()
arr[0] = 1
for i in range(1, len(arr)):
if arr[i] - arr[i - 1] > 1:
arr[i] = arr[i - 1] + 1
return arr[len(arr) - 1]
if __name__ == "__main__":
so = Solution()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17