注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
本帖最后由 zyyymsfd您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式 ,但是我没想出来。- **Beauty of Array**
- The beauty of an array `a` of length `m` is defined as the number of integers `i` (0 ≤ i < m) such that a[i] = i.
- Given an array `arr` of n integers, find the maximum possible beauty of the array after performing the following operation any number of times:
- * Choose some i (0 ≤ i < length of the array) and delete arr[i], without changing the order of the remaining elements.
- ---
- ### **Function Description**
- Complete the function `maximizeBeauty` in the editor below.
- `maximizeBeauty` has the following parameter:
- * `int arr[n]`: the given array
- **Returns**
- * `int`: the maximum possible beauty of the array
- ---
- ### **Constraints**
- * 1 ≤ n ≤ 2000
- * 1 ≤ arr[i] ≤ 10^9
- ---
- ### **Example**
- ```
- arr = [1,3,2,5,4,5,3]
- One optimal sequence of operations is:
- 1. Choose i = 2, delete arr[2] = 3 → arr = [1,3,2,5,4,5,3]
- 2. Choose i = 6, delete arr[6] = 3 → arr = [1,2,5,4,5]
- The beauty of arr is 4 since arr[0]=1, arr[1]=2, arr[3]=4, arr[4]=5.
- Return 4.
- ```
- Note that there can be more than one final array with maximum beauty.
复制代码 |