forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_1243.java
26 lines (24 loc) · 838 Bytes
/
_1243.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.fishercoder.solutions;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class _1243 {
public static class Solution1 {
public List<Integer> transformArray(int[] arr) {
int[] copy;
do {
copy = Arrays.copyOf(arr, arr.length);
for (int i = 1; i < arr.length - 1; i++) {
if (copy[i] < copy[i - 1] && copy[i] < copy[i + 1]) {
arr[i]++;
} else if (copy[i] > copy[i - 1] && copy[i] > copy[i + 1]) {
arr[i]--;
}
}
} while (!Arrays.equals(copy, arr));
return Arrays.stream(arr)
.boxed()
.collect(Collectors.toList());
}
}
}