-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayTransformation.cpp
34 lines (34 loc) · 1003 Bytes
/
ArrayTransformation.cpp
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
class Solution {
public:
bool isSame(vector<int> v1, vector<int> v2){
for(int i = 0; i< v1.size(); i++){
if(v1[i] != v2[i]){
return false;
}
}
return true;
}
vector<int> transformArray(vector<int>& arr) {
vector<int> nextday(arr.begin(), arr.end());
for(int i = 1; i<arr.size()-1;i++){
if(arr[i-1] < arr[i] && arr[i]> arr[i+1]){
nextday[i] -= 1;
}
if(arr[i-1] > arr[i] && arr[i] < arr[i+1] ){
nextday[i] += 1;
}
}
while(isSame(arr, nextday) == false){
arr = nextday;
for(int i = 1; i<arr.size()-1;i++){
if(arr[i-1] < arr[i] && arr[i]> arr[i+1]){
nextday[i] -= 1;
}
if(arr[i-1] > arr[i] && arr[i] < arr[i+1] ){
nextday[i] += 1;
}
}
}
return nextday;
}
};