本文共 899 字,大约阅读时间需要 2 分钟。
class Solution { public int[] replaceElements(int[] arr) { int l = arr.length; int[] ans = new int[l]; for(int i=0;i
class Solution { public int[] replaceElements(int[] arr) { int[] res = new int[arr.length]; int max = -1; for (int i = arr.length - 1; i >= 0; i--) { res[i] = max; max = Math.max(arr[i], max); } return res; }}
package com.company;public class replaceElements { public static void main(String[] args){ replaceElements test = new replaceElements(); int [] a = {17,18,5,4,6,1}; int [] res = test.replaceElements(a); for(int i = 0; i= 0; i--) { int t = arr[i]; arr[i] = max; max = Math.max(t, max); } return arr; }}
转载地址:http://hejvi.baihongyu.com/