Skip to content

Commit 3a6231b

Browse files
authored
Create 1968-Array-With-Elements-Not-Equal-to-Average-of-Neighbors.cpp
1 parent 55a2f29 commit 3a6231b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
vector<int> rearrangeArray(vector<int>& nums) {
4+
vector<int> ans;
5+
for(int i=1;i<nums.size()-1;i++){
6+
int a=nums[i-1];
7+
int b=nums[i];
8+
int c=nums[i+1];
9+
if(a>b && b>c || a<b && b<c) swap(nums[i],nums[i+1]);
10+
}
11+
return nums;
12+
}
13+
};

0 commit comments

Comments
 (0)