1299. 将每个元素替换为右侧最大元素 - 力扣(LeetCode)
class Solution {
public:vector<int> replaceElements(vector<int>& arr) {int n = arr.size();vector<int> res(n, -1);for(int i = n-2; i >= 0; --i){if(arr[i+1] > res[i+1]) res[i] = arr[i+1];else res[i] = res[i+1];}return res;}
};