class Solution {
public int[] replaceElements(int[] arr) {
int rightMax = 0;
for (int i = 0; i < arr.length - 1; i++) {
for (int j = i+1; j < arr.length; j++) {
if(rightMax < arr[j])
rightMax = arr[j];
}
arr[i] = rightMax;
rightMax = 0;
}
arr[arr.length - 1] = -1;
return arr;
}
}
'JAVA > leetcode' 카테고리의 다른 글
[LeetCode] Array - Sort Array By Parity - Two-pointer (0) | 2021.08.05 |
---|---|
[LeetCode] Array - Move Zeroes - Two-pointer (0) | 2021.08.05 |
[LeetCode] Array - Valid Mountain Array (0) | 2021.08.05 |
[LeetCode] Array - Check If N and Its Double Exist (0) | 2021.08.05 |
[LeetCode] Array - Remove Duplicates from Sorted Array !! (0) | 2021.08.05 |