forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1243.cpp
More file actions
26 lines (26 loc) · 634 Bytes
/
1243.cpp
File metadata and controls
26 lines (26 loc) · 634 Bytes
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
class Solution
{
public:
vector<int> transformArray(vector<int>& arr)
{
bool change = true;
vector<int> tmp = arr;
while (change)
{
change = false;
for (int i = 1; i < arr.size() -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;
}
return arr;
}
};