Hard
Array
Math
Greedy
2366. Minimum Replacements to Sort the Array
You are given a 0-indexed integer array nums
. In one operation you can replace any element of the array with any two elements that sum to it.
nums = [5,6,7]
. In one operation, we can replace nums[1]
with 2
and 4
and convert nums
to [5,2,4,7]
.Return the minimum number of operations to make an array that is sorted in non-decreasing order.
Example 1:
Example 2:
Constraints:
nums.length
<= 105nums[i]
<= 109從最後一個數字往前找,如果比上一個數字大代表需要被分割,
JimAug 30, 2023