forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1243.java
More file actions
20 lines (20 loc) · 646 Bytes
/
1243.java
File metadata and controls
20 lines (20 loc) · 646 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public List<Integer> transformArray(int[] arr) {
Boolean change = true;
int[] tmp = arr.clone();
while (change) {
change = false;
for (int i = 1; i < arr.length -1; i++) {
if (arr[i] > arr[i-1] && arr[i] > arr[i+1]) {
tmp[i]--; change = true;
} else if (arr[i] < arr[i-1] && arr[i] < arr[i+1]) {
tmp[i]++; change = true;
}
}
arr = tmp.clone();
}
List<Integer> res = new ArrayList();
for (int i : arr) res.add(i);
return res;
}
}