-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1243_transform_array.cc
More file actions
42 lines (39 loc) · 899 Bytes
/
1243_transform_array.cc
File metadata and controls
42 lines (39 loc) · 899 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <tuple>
#include <queue>
#include <stack>
using namespace::std;
class Solution {
public:
vector<int> transformArray(vector<int>& arr) {
int n = arr.size();
if (n < 3) return arr;
while (1) {
int changed = 0, pre = arr[0];
for (int i = 1; i < n - 1; ++i) {
int tmp = arr[i];
if (arr[i] > pre && arr[i] > arr[i + 1]) {
--arr[i];
changed = 1;
} else if (arr[i] < pre && arr[i] < arr[i + 1]) {
++arr[i];
changed = 1;
}
pre = tmp;
}
if (!changed)
break;
}
return arr;
}
};
int main()
{
return 0;
}